-
Notifications
You must be signed in to change notification settings - Fork 1
/
library.py
42 lines (34 loc) · 1.44 KB
/
library.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
TEXT = "text"
FULLTEXT = "full_text"
EXTENDEDTWEET = "extended_tweet"
RETWEETEDSTATUS = "retweeted_status"
def getTweetText(jsonData):
text = ""
if TEXT in jsonData:
text = jsonData[TEXT]
if EXTENDEDTWEET in jsonData and \
FULLTEXT in jsonData[EXTENDEDTWEET]:
text = jsonData[EXTENDEDTWEET][FULLTEXT]
if RETWEETEDSTATUS in jsonData and \
EXTENDEDTWEET in jsonData[RETWEETEDSTATUS] and \
FULLTEXT in jsonData[RETWEETEDSTATUS][EXTENDEDTWEET]:
text = jsonData[RETWEETEDSTATUS][EXTENDEDTWEET][FULLTEXT]
return(text)
from datetime import datetime, timedelta
DATEFORMATTWITTER = "%a %b %d %H:%M:%S %z %Y"
DATEFORMATGTD = "%Y%m%d"
SUMMERTIMEDATE = datetime.strptime("Sun Mar 29 02:00:00 +0000 2020",DATEFORMATTWITTER)
WINTERTIMEDATE = datetime.strptime("Sun Oct 25 03:00:00 +0000 2020",DATEFORMATTWITTER)
def getTweetDate(jsonData,dateFormat=DATEFORMATGTD):
dateString = jsonData["created_at"]
dateData = datetime.strptime(dateString,DATEFORMATTWITTER)+timedelta(hours=1)
if dateData >= SUMMERTIMEDATE:
if dateData >= WINTERTIMEDATE: sys.exit("cannot happen")
dateData += timedelta(hours=1)
return(dateData.strftime(dateFormat))
DATEFORMATSATD = "%Y%m%d"
def stringArrayToDates(stringList,dateFormat=DATEFORMATSATD):
return([datetime.strptime(str(date),dateFormat) for date in stringList])
def main(argv): pass
if __name__ == "__main__":
sys.exit(main(sys.argv))