-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_function.py
executable file
·61 lines (51 loc) · 2.11 KB
/
lambda_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
import tweepy
import requests
import pandas as pd
import numpy as np
import datetime
def lambda_handler(event, context):
pskey={}
with open("pskeys/pskey.json") as file:
pskey = json.loads(file.read())
# Consumer keys and access tokens, used for OAuth
consumer_key = pskey["consumer_key"]
consumer_secret = pskey["consumer_secret"]
access_token = pskey["access_token"]
access_token_secret = pskey["access_token_secret"]
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# Store access keys in a way to send to Twitter
api = tweepy.API(auth)
def buildTweet(argument1):
tweet = "The president will be in Maryland today, " + argument1 + ". For more information, visit https://factba.se/topic/calendar."
sendTweet(tweet)
def sendTweet(content):
api.update_status(content)
#import president's schedule as json to dataframe
urlschedule = 'https://factba.se/rss/calendar-full.json'
importschedule = requests.get(urlschedule)
jsonschedule = importschedule.json()
scheduledf = pd.DataFrame(jsonschedule)
#import today's date
def getDate():
now = datetime.datetime.now()
date = now.strftime('%Y-%m-%d')
return date
#search for md locations only for today
date = getDate()
scheduledf = scheduledf.replace(np.nan, '', regex=True)
psdate = scheduledf[scheduledf['date'].str.contains(date)]
if (len(psdate) > 0):
irow = psdate.iterrows()
mdgov = ["MD", "Gaylord", "James J. Rowley", "Camp David", "Walter Reed", "Hagerstown", "Joint Base Andrews", "Aberdeen", "Fort Meade", "Fort Detrick", "Naval Academey"]
for m in mdgov:
mdsearch = psdate[psdate['details'].str.contains(m) | psdate['location'].str.contains(m)]
if (len(mdsearch) > 0):
irow = mdsearch.iterrows()
for i in irow:
print(i[1]['details'])
print(i[1]['location'])
buildTweet(i[1]['date'])
return 'Hello from Lambda'