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
/
update_database.py
55 lines (45 loc) · 1.82 KB
/
update_database.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
# Author: Nanda H Krishna (https://github.com/nandahkrishna)
import pickle as pkl
import slack
import pyrebase
from credentials.keys import *
tars_token = keys["slack"]
tars = slack.WebClient(token=tars_token)
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)
tars_db = tars_fb.database()
all_users = tars.users_list().data["members"]
with open("credentials/all_users.pkl", "wb") as f:
pkl.dump(all_users, f)
admins = []
tas = []
orientees = []
groups = tars.groups_list().data["groups"]
for group in groups:
if group["id"] == keys["server_admin"]:
admins = group["members"]
if group["id"] == keys["sf_ta"]:
tas = group["members"]
if group["id"] == keys["orientation_assignments"] or group["id"] == keys["orientation_project"]:
orientees += group["members"]
admins = set(admins)
tas = set(tas)
current_orientees = set(tars_db.child(keys["key_fb_tars"]).child("orientee").get().val())
orientees = set(orientees)
orientees -= tas
orientees -= current_orientees
orientees_not_added = []
for i in orientees:
orientees_not_added.append(tars.users_info(user=i).data["user"]["profile"]["real_name"])
tars_db.child(keys["key_fb_tars"]).child("ta").remove()
tars_db.child(keys["key_fb_tars"]).child("admin").remove()
for i in tas:
tars_db.child(keys["key_fb_tars"]).child("ta").update({str(i): str(tars.users_info(user=i).data["user"]["profile"]["real_name"])})
for i in admins:
tars_db.child(keys["key_fb_tars"]).child("admin").update({str(i): str(tars.users_info(user=i).data["user"]["profile"]["real_name"])})
tars.chat_postMessage(channel=keys["tars_admin"], text="Orientees who haven't been added to the database: " + str(orientees_not_added))