-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
105 lines (88 loc) · 3.25 KB
/
main.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
import insertEvent
import openpyxl
months = { "January" : "01",
"February" : "02",
"March" : "03",
"April" : "04",
"May" : "05",
"June" : "06",
"July" : "07",
"August" : "08",
"September" : "09",
"October" : "10",
"November" : "11",
"December" : "12" }
# Converts start time to military time and adds seconds to the end
def getStart(period):
hour = int(period.rsplit(':', 1)[0])
if(hour > 7 and hour < 13):
return str(hour) + ':' + period.rsplit(':', 1)[1] + ':00'
else:
return str(hour + 12) + ':' + period.rsplit(':', 1)[1] + ':00'
# Converts end time to military time and adds seconds to the end
def getEnd(period):
hour = int(period.rsplit(':', 1)[0])
if(hour > 9 and hour < 13):
return str(hour) + ':' + period.rsplit(':', 1)[1] + ':00'
else:
return str(hour + 12) + ':' + period.rsplit(':', 1)[1] + ':00'
# Converts time in standard time format for Google Calendar API, then books event
def convertTime(week, day):
if week[day].value != None and week[day].value != "OFF":
date = week[day[0] + '5'].value.rsplit(". ", 1)[1]
if(date[0] == " ") :
date = date[1:3]
start = getStart(week[day].value.rsplit('-', 1)[0])
end = getEnd(week[day].value.rsplit('-', 1)[1])
# Adds 0 in front of single digit hours
if(start[0] != '1') :
start = "0" + start
# Adds 0 in front of single digit hours
if(end[0] != '1') :
end = "0" + end
# Decides whether to use the first month or the second month
if(int(date) < 7) :
month = month2
else :
month = month1
# Sets up correct time format for Google Calendar API JSON file
start = year + "-" + months[month] + "-" + date + "T" + start + "-04:00"
end = year + "-" + months[month] + "-" + date + "T" + end + "-04:00"
# Event JSON file
eventInfo = {
'summary': 'QBPL Cyber Center',
'location': 'Queens Library (Central) 89-11 Merrick Blvd, Jamaica, NY 11432',
'start': {
'dateTime': start,
'timeZone': 'America/New_York',
},
'end': {
'dateTime': end,
'timeZone': 'America/New_York',
},
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'popup', 'minutes': 60},
],
},
}
# Creates event for Google Calendar
insertEvent.bookEvent(eventInfo)
print("Event created: Success!")
week = openpyxl.load_workbook('week.xlsx')
week = week.get_sheet_by_name('Sheet1')
# Gets year and months from workbook
year = week['A3'].value.rsplit(', ', 1)[1]
month1 = week['A3'].value.rsplit(' - ', 1)[0]
month2 = week['A3'].value.rsplit(' - ', 1)[1].rsplit(', ', 1)[0]
# Trims numbers at the end of the month
month1 = month1[:-3]
month2 = month2[:-3]
convertTime(week,'C16')
convertTime(week,'E16')
convertTime(week,'G16')
convertTime(week,'I16')
convertTime(week,'K16')
convertTime(week,'M16')
convertTime(week,'O16')