-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
204 lines (161 loc) · 5.46 KB
/
utils.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
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
# Description: This file contains all the functions that are used to validate the data that is being sent to the database
import datetime
# All validator functions
'''
Handling all is validators
'''
# Check if its a valid SIG
def isValidSigName(db_GDSC, sig_name):
sig_collection = db_GDSC["sigs"]
x = sig_collection.find_one({"sig_name": sig_name})
if x == None:
return 0 # Dint find such a SIG
else:
return 1 # Found the SIG
# Check if its a valid discord username on WEC database
def isValidDiscordUsername(db_GDSC, discord_username):
user_collection = db_GDSC["users"]
x = user_collection.find_one({"discord_username": discord_username})
if x == None:
return 0 # Dint find such a discord_username
else:
return 1 # Found the discord_username
# Check if person is a head
def isHead(db_GDSC, discord_username):
user_collection = db_GDSC['users']
x = user_collection.find_one({'discord_username': discord_username})
if x['head'] == True:
return 1 # If user is head
else:
return 0 # User not head
def isDiscordUsernameOnDatabase(db_GDSC, discord_username):
user_collection = db_GDSC['users']
x = user_collection.find_one({'discord_username': discord_username})
if x == None:
# not in WEC
return 0
else:
# in WEC
return 1
def isExecutive(db_GDSC, discord_username):
user_collection = db_GDSC['users']
x = user_collection.find_one({'discord_username': discord_username})
# EM-Executive Member
if x['role'] == "EM":
return 1 # If executive Member
else:
return 0 # Not an executive Member
'''
Handling all finder functions
'''
def findUserInfo(db_GDSC, discord_username):
user_collection = db_GDSC["users"]
x = user_collection.find_one({"discord_username": discord_username})
if (x['role'] == 'EM'):
role = 'Executive Member'
else:
role = 'Member'
return f'''
Name: {x["username"]}\nRole: {role}\nEmail: {x["email"]}\nGithub: {x["github"]}\nSIG: {x["sig"]}\nYear: {x["year"]}\nBranch: {x["branch"]}\nPhone: {x["phone"]}\nDiscord Username: {x["discord_username"]}
'''
def findSIGMembers(db_GDSC, sig_name):
sig_collection = db_GDSC["users"]
x = sig_collection.find({"sig": sig_name})
if x == None:
return 0
else:
L = []
for i in x:
L.append(i["username"])
if (len(L) == 0):
return "No members in this SIG"
else:
return L
def findSigInfo(db_GDSC, sig_name):
sig_collection = db_GDSC["sigs"]
data = {
"sig_name": sig_name,
}
x = sig_collection.find_one(data)
print(x)
return f'''
SIG Name: {sig_name}\nSIG Head: {x["sig_head"]}\nSIG Description: {x["sig_desc"]}\nSIG Members: {findSIGMembers(db_GDSC, sig_name)}
'''
'''
Handling all adding stuff
'''
def addSIG(db_GDSC, sig_name, sig_head):
sig_collection = db_GDSC["sig"]
data = {
"sig": sig_name,
"head": sig_head
}
sig_collection.insert_one(data)
def addEvent(db_GDSC, date, event_Name, venue, time, about, tech_or_tech):
event_collection = db_GDSC["events"]
data = {
"date": date,
"event_Name": event_Name,
"venue": venue,
"time": time,
"about": about,
"tech_or_tech": tech_or_tech,
}
event_collection.insert_one(data)
def addUserToSig(db_GDSC, sig, discord_username):
sig_collection = db_GDSC["sig"]
x = sig_collection.find_one({"sig": sig})
if x == None:
return 0
else:
sig_collection.update_one(
{"sig": sig}, {"$push": {"members": discord_username}})
return 1
def upcomingEvents(db_GDSC):
# for upcoming events with reference to current date where current date is todays date get from datetime module
events_collection = db_GDSC["events"]
x = events_collection.find().sort("event_date")
L = []
for i in x:
if i["event_date"] > datetime.datetime.now():
L.append(i["event_name"])
return L
def displayPastEvents(db_GDSC):
# display the past events with reference to current date where current date is todays date get from datetime module
events_collection = db_GDSC["events"]
x = events_collection.find().sort("event_date")
L = []
for i in x:
if i["event_date"] < datetime.datetime.now():
L.append(i["event_name"])
return L
def eventInfo(db_GDSC, event_name):
events_collection = db_GDSC["events"]
x = events_collection.find_one({"event_name": event_name})
if x == None:
return 0
else:
return f'''
Event Name: {x["event_name"]}\nDate: {x["event_date"]}\nTime: {x["event_time"]}\nVenue: {x["event_venue"]}\nAbout: {x["event_description"]}\nTechical Event: {x["event_T"]}
'''
def displayNonTechnicalEvents(db_GDSC):
events_collection = db_GDSC["events"]
x = events_collection.find({"event_T": False})
L = []
for i in x:
L.append(i["event_name"])
return L
def displayTechnicalEvents(db_GDSC):
events_collection = db_GDSC["events"]
x = events_collection.find({"event_T": True})
L = []
for i in x:
L.append(i["event_name"])
return L
def isValidEventName(db_GDSC, event_name):
event_collection = db_GDSC["events"]
x = event_collection.find_one({"event_name": event_name})
if x == None:
return 0 # Dint find such a Event
else:
return 1 # Found the Event