-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogleapi.py
More file actions
212 lines (162 loc) · 7.65 KB
/
googleapi.py
File metadata and controls
212 lines (162 loc) · 7.65 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from __future__ import print_function
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
import datetime
from datetime import *
import pytz
import time
tme = time
from replit import db
# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/classroom.student-submissions.me.readonly', 'https://www.googleapis.com/auth/classroom.courses.readonly']
'''
caribou, all the 705 stuff, back to the classroom at 88mph
'''
convmonths = ["Janurary","Feburary","March","April","May","June","July","August","September","October","November","December"]
def main():
global convmonhts
classes805 = [
'Homelands Spirit Hawks',
'Caribou Math Contest',
'805 Music',
'805 PE',
'teCH-eray 805',
'805 - French, Arts',
'805 ELC']
"""Shows basic usage of the Classroom API.
Prints the names of the first 10 courses the user has access to.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('duedate/token.json'):
creds = Credentials.from_authorized_user_file('duedate/token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
flow = InstalledAppFlow.from_client_secrets_file(
'duedate/cred.json',SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('duedate/token.json', 'w') as token:
token.write(creds.to_json())
service = build('classroom', 'v1', credentials=creds)
# Call the Classroom API
results = service.courses().list(pageSize=10).execute()
courses = results.get('courses', [])
if not courses:
print('No courses found.')
else:
shortcutday = datetime.now(pytz.timezone('US/Eastern'))
ymd = {
'year' : int(shortcutday.strftime("20%y")),
'month' : int(shortcutday.strftime("%m")),
'day' : int(shortcutday.strftime("%d"))}
due = []
for course in courses:
try:
work = service.courses().courseWork().list(courseId=course[u'id']).execute()
if course['name'] in classes805:
assignnum = 0
for item in work['courseWork']:
try:
from bot_func import alter
ddymd = work['courseWork'][assignnum]['dueDate']
formatteddue = "\nDue : " + alter([int(work['courseWork'][assignnum]['dueDate']['month']),int(work['courseWork'][assignnum]['dueDate']['day'])])
if ddymd['year'] >= ymd['year'] and ddymd['month'] >= ymd['month'] and ddymd['day'] >= ymd['day']:
due.append("**" + str(work['courseWork'][assignnum]['title'])+"**"+ str(formatteddue))
elif ddymd['year'] > ymd['year']:
due.append("**" + str(work['courseWork'][assignnum]['title'])+"**"+ str(formatteddue))
elif ddymd['year'] >= ymd['year'] and ddymd['month'] > ymd['month']:
due.append("**" + str(work['courseWork'][assignnum]['title'])+"**"+ str(formatteddue))
except:
pass
assignnum += 1
else:
pass
except KeyError:
pass
if not due:
due.append("Woohoo, no work due soon")
return due
def main2():
classes705 = [
'The Learning Strikes Back',
'705 Music',
'705 PE',
'705 - Cobo- tech',
'705',
'705 - Linthwaite (ROTARY) 21/22',
'Back to the Classroom (at 88 mph) - Part I']
"""Shows basic usage of the Classroom API.
Prints the names of the first 10 courses the user has access to.
"""
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('duedate/danieltoken.json'):
creds = Credentials.from_authorized_user_file('duedate/danieltoken.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
flow = InstalledAppFlow.from_client_secrets_file(
'duedate/cred.json',SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('duedate/danieltoken.json', 'w') as token:
token.write(creds.to_json())
service = build('classroom', 'v1', credentials=creds)
# Call the Classroom API
results = service.courses().list(pageSize=10).execute()
courses = results.get('courses', [])
if not courses:
print('No courses found.')
else:
shortcutday = datetime.now(pytz.timezone('US/Eastern'))
ymd = {
'year' : int(shortcutday.strftime("20%y")),
'month' : int(shortcutday.strftime("%m")),
'day' : int(shortcutday.strftime("%d"))}
due = []
for course in courses:
try:
work = service.courses().courseWork().list(courseId=course[u'id']).execute()
if course['name'] in classes705:
assignnum = 0
for item in work['courseWork']:
try:
from bot_func import alter
ddymd = work['courseWork'][assignnum]['dueDate']
formatteddue = "\nDue : " + alter([int(work['courseWork'][assignnum]['dueDate']['month']),int(work['courseWork'][assignnum]['dueDate']['day'])])
if ddymd['year'] >= ymd['year'] and ddymd['month'] >= ymd['month'] and ddymd['day'] >= ymd['day']:
due.append("**" + str(work['courseWork'][assignnum]['title'])+"**" + str(formatteddue))
elif ddymd['year'] > ymd['year']:
due.append("**" + str(work['courseWork'][assignnum]['title'])+"**" + str(formatteddue))
elif ddymd['year'] >= ymd['year'] and ddymd['month'] > ymd['month']:
due.append("**" + str(work['courseWork'][assignnum]['title'])+"**"+ str(formatteddue))
except:
pass
assignnum += 1
else:
pass
except KeyError:
pass
#No work?!?!?
if not due:
due.append("Woohoo, no work due soon")
return due
if __name__ == '__main__':
main()
main2()
#def homework(year,month,day):