This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
all_day_ta_hours.py
64 lines (59 loc) · 2 KB
/
all_day_ta_hours.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
from slack_bolt import App
from credentials.keys import *
import datetime
import pyrebase
tars_token = keys["slack"]
tars_secret = keys["signing_secret"]
tars_id = keys["tars"]
tars = App(token=tars_token, signing_secret=tars_secret)
sf_ta = keys["sf_ta"]
ta_group = keys["ta_group"]
tars_fb_config = {
"apiKey": keys["tars_fb_key"],
"authDomain": keys["tars_fb_ad"],
"databaseURL": keys["tars_fb_url"],
"storageBucket": keys["tars_fb_sb"],
}
tars_fb = pyrebase.initialize_app(tars_fb_config)
db = tars_fb.database()
ts = open("credentials/message.txt", "r").read()
q = "*Teaching Assistant Hours for " + ts + "*"
poll = db.child(keys["key_fb_tars"]).child("polls").get().val()
poll = dict(zip(poll.keys(), poll.values()))
for key in poll.keys():
value = poll[key]
if value["message"][0]["text"]["text"] == q:
poll = value
ts = key.replace(".", "-")
break
db.child(keys["key_fb_tars"]).child("polls").child(ts).remove()
text = q + "\n"
for block in poll["message"][1:-3]:
try:
text += (
block["text"]["text"].split("`")[0].strip()
+ " "
+ block["text"]["text"].split("`")[2]
+ "\n"
)
except:
text += block["text"]["text"] + "\n"
tars.client.chat_delete(channel=ta_group, ts=ts.replace("-", "."))
tars.client.chat_postMessage(channel=sf_ta, text=text)
tars.client.chat_postMessage(channel=keys["orientation_assignments"], text=text)
tars.client.chat_postMessage(channel=keys["orientation_project"], text=text)
# tars.client.chat_postMessage(channel=keys["general"], text=text)
i = datetime.date.today().weekday() + 2
i = i % 7
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
message = tars.client.chat_postMessage(
channel=ta_group,
text="<@"
+ tars_id
+ '> poll "Teaching Assistant Hours for '
+ days[i]
+ '" "11:00-12:30" "14:00-16:00" "16:00-18:00" "18:00-20:00"',
as_user=True,
)
with open("credentials/message.txt", "w") as f:
f.write(days[i])