-
Notifications
You must be signed in to change notification settings - Fork 0
/
myTime.py
executable file
·157 lines (133 loc) · 4.88 KB
/
myTime.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import datetime
import sys
sys.path.append("/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages")
import iso8601
import pytz
def getZone(uni):
zone = {
'University of California--Davis' : "America/Los_Angeles",
'Southwestern University': "America/Chicago",
'Rensselaer Polytechnic Institute' : "America/New_York",
'Brown University' : "America/New_York",
'New York University' : "America/New_York",
'Rutgers, the State University of NJ' :"America/New_York" ,
'Syracuse University' : "America/New_York",
'UCLA' : "America/Los_Angeles",
'Purdue University--West Lafayette' : "America/New_York",
'Kenyon College' : "America/New_York",
'Colorado College': "America/Phoenix",
'Colorado School of Mines': "America/Phoenix",
'Cornell University': "America/New_York",
'Trinity College' : "America/Chicago",
'Middlebury College' : "America/New_York",
'University of Alabama' : "America/Chicago",
'Emory U' : "America/New_York",
'Columbia': "America/New_York",
'Haverford College' : "America/New_York",
'University of California--Santa Barbara' : "America/Los_Angeles",
'Lafayette College' : "America/New_York",
'Lawrence University': "America/Chicago",
'Princeton' : "America/New_York",
'Georgetown University' : "America/New_York",
'Harvard' : "America/New_York",
'Worcester Polytechnic Institute' : "America/New_York",
'University of Southern California' : "America/Los_Angeles",
'University of Wisconsin--Madison' : "America/Chicago",
'Auburn University' : "America/Chicago",
'Northwestern Univeristy' : "America/Chicago",
'Rhodes College' : "America/Chicago",
'Florida State University' : "America/New_York",
'University of Miami' : "America/New_York",
'University of Chicago' : "America/Chicago",
'Miami University--Oxford' : "America/New_York",
'DePauw University' : "America/New_York",
'California Insititute of Technology' :"America/Los_Angeles",
'University of New Hampshire' : "America/New_York",
'Smith College' : "America/New_York",
'Bard College' : "America/New_York",
'Texas A&M University--College Station' : "America/Chicago",
'Grinnell College' : "America/Chicago",
'Lewis & Clark College' : "America/Los_Angeles",
'Wake Forest University' : "America/New_York",
'University of Denver' : "America/Phoenix",
'Brigham Young University--Provo' : "America/Phoenix",
'Indiana University' : "America/New_York",
'Rice University' : "America/Chicago",
'Pennsylvania State University--University Park' : "America/New_York",
'Ohio State University--Columbus' : "America/New_York",
'Clemson University': "America/New_York",
'Northeastern University' : "America/New_York",
'St. Lawrence University' : "America/New_York",
'Pepperdine University' : "America/Los_Angeles",
'Stanford' :"America/Los_Angeles"
}
return zone[uni]
def timeSlot(hour):
if hour>= 6 and hour<9:
return "earlyMorning"
elif hour >=9 and hour<12:
return "lateMorning"
elif hour >=12 and hour<15:
return "earlyAfternoon"
elif hour >=15 and hour <18:
return "lateAfternoon"
elif hour >=18 and hour <21:
return "evening"
elif hour >=21 and hour <=24:
return "night"
elif hour >= 0 and hour<3:
return "lateNight"
elif hour >=3 and hour <6:
return "beforeSunRise"
else:
return "other"
def timeOfWeek(dayOfWeek):
if dayOfWeek == "Saturday" or dayOfWeek == "Sunday":
return "weekend"
else:
return "weekday"
def adjustTimezone(timestamp, uni):
if uni == None:
print None
return timestamp
zone = pytz.timezone(getZone(uni))
isotime = iso8601.parse_date(timestamp)
return isotime.astimezone(zone).isoformat()
def myTime(timestamp, uni = None):
dct = {}
timestamp = timestamp.strip('"')
timestamp = adjustTimezone(timestamp, uni)
date, rest = timestamp.split("T")
if "+" in rest:
hour = rest.split("+")[0]
elif "-" in rest:
hour = rest.split("-")[0]
yyyy, mm, dd = date.split("-")
hour, minute, second = hour.split(":")
dct["date"] = date
dct["yyyy"] = int(yyyy)
dct["mm"] = int(mm)
dct["dd"] = int(dd)
dct["hour"] = int(hour)
dct["minute"] = int(minute)
dct["second"] = int(second)
dct["DOW"] = (datetime.date(dct["yyyy"], dct["mm"],dct["dd"])).strftime("%A")
dct["MOY"] = (datetime.date(dct["yyyy"], dct["mm"],dct["dd"])).strftime("%B")
dct["TOD"] = timeSlot(dct["hour"])
dct["TOW"] = timeOfWeek(dct["DOW"])
dct["TODW"] = str(dct["TOD"])+str(dct["DOW"])
return dct
def getTime(posts, uni, DOW, HOD, MOY, TOD, TOW, TODW):
for post in posts[uni]:
time = myTime(post["time"], uni)
DOW += [time["DOW"]]
HOD += [time["hour"]]
MOY += [time["MOY"]]
TOD += [time["TOD"]]
TOW += [time["TOW"]]
TODW += [time["TODW"]]
return DOW, HOD, MOY, TOD, TOW, TODW
def splitTime(dateString):
date, rest = dateString.split("T")
hour = rest.split("+")[0]
return date, hour