-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRefresh.py
More file actions
99 lines (78 loc) · 4.08 KB
/
Refresh.py
File metadata and controls
99 lines (78 loc) · 4.08 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
from google.cloud import datastore
from send_sms import sendMessage
import yagmail
import re
import config as cf
"""
I believe that this does not also add the current courses, and that the /schedule cron job has to be run
"""
def Refresh(datastore_client):
global client
client = datastore_client
updateMasterEntity()
if cf.dateObj.month > 5 and cf.dateObj.month < 9:
# It is summer, don't send the message to users but make sure they don't get notified when a seat opens during freshman adjustment
print("It is summer")
else:
# It is not summer.
UpdateUsers()
ClearCourses()
"""
Updates the master entity to add new fields for the new semester, such as emailsSentFall2021
"""
def updateMasterEntity():
query = client.query(kind='masterEntity')
ME = list(query.fetch())[0]
# Check if field exists already to avoid overwriting
fieldsDict = {"listFields":
{
"fields": [cf.dateObj.courseList, cf.dateObj.userList],
"default": []
},
"intFields":
{
"fields": [cf.dateObj.emailsSent,
cf.dateObj.textsSent,
cf.dateObj.numUsers],
"default": 0
}
}
for fieldType in ["listFields", "intFields"]:
for field in fieldsDict[fieldType]["fields"]:
try:
# WIll error out if field doesn't exist, but if it does exist will do nothing
if ME[field] == "test":
pass
except:
ME[field] = fieldsDict[fieldType]["default"]
client.put(ME)
# Sends a welcome back message. Currently commented out
def SendMessage(username):
yag = yagmail.SMTP('spotcheckwes@gmail.com',
oauth2_file="oauth2_creds.json")
# The text welcome back message has to be shorter since Twilio counts every 160 characters as a text message so sending a long text is pricey
welcomeBackMessageEmail = "Hello SpotCheck Users! This month is the start of a new pre-reg period, and SpotCheck is once again open for business! To be alerted when a seat opens in a class you want during adjustment, simply go to https://spotcheck.space and sign up. The earlier you sign up, the quicker you'll be notified when a seat opens! All account information has been deleted at the end of last semester so you will have to sign up again. If you have any SpotCheck success stories, please tell me about them at spotcheckwes@gmail.com! \n\nAnd to all my fellow seniors doing their final pre-reg, it’s been a pleasure knowing you all. Let’s make this last semester the best one yet. \n\nLove, \nSpotCheck"
welcomeBackMessageText = "This month is the start of a new pre-reg period, and SpotCheck is open for business! To be alerted when a seat opens in a class you want during adjustment, go to https://spotcheck.space and sign up. All account information has been deleted at the end of last semester so you will have to sign up again. \n\nAnd to all my fellow seniors doing their final pre-reg, it’s been a pleasure knowing you all. Let’s make this last semester the best one yet \n\nLove, \nSpotCheck"
if re.search("\d{9,10}", username): # Text
sendMessage(username, welcomeBackMessageText)
elif re.search("@", username): # Email
yag.send(username, 'SpotCheck Is Now Active Again!',
welcomeBackMessageEmail)
"""
Sends all of the current users a message saying that SpotCheck is starting again and then deletes the user entity
"""
def UpdateUsers():
query = client.query(kind='user')
results = list(query.fetch())
for result in results:
key = result.key
username = result["username"]
# SendMessage(username)
client.delete(key)
def ClearCourses():
query = client.query(kind='course')
print('made it past query for all courses in clearcourses')
results = list(query.fetch())
for result in results:
key = result.key
client.delete(key)