-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbatch_scripts.py
More file actions
701 lines (635 loc) Β· 24.6 KB
/
batch_scripts.py
File metadata and controls
701 lines (635 loc) Β· 24.6 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
#!/bin/bash/python3
import base64
from json import ObjectId
import csv
import getpass
import json
import os
import readline
import requests
import subprocess
from typing import Any, Callable, List
import sys
# Constants
VALID_STATUSES = {
'1': 'Applied',
'2': 'Accepted',
'3': 'Waitlisted',
'4': 'Declined',
'5': 'Confirmed',
'6': 'Withdrawn',
'7': 'Checked-in'
}
VALID_REVIEWER_STATUSES = {
'1': 'None',
'2': 'Poor',
'3': 'Weak',
'4': 'Average',
'5': 'Strong',
'6': 'Outstanding',
'7': 'Whitelist'
}
BATCH_ACTIONS = {
'1': 'updateStatus',
'2': 'dayOf',
'3': 'weekOf',
'4': 'downloadResume',
'5': 'inviteUsers',
'6': 'getHackers',
'7': 'updateReviewerStatus'
}
LOG_VERBOSITIES = {
'0': 'None',
'1': 'Error',
'2': 'Warning',
'3': 'Info'
}
CHOSEN_VERBOSITY = 3
API_URL = 'https://api.mchacks.ca'
s = requests.Session()
def _print(msg, msgType=3, index=None, total=None):
"""
Wrapper around print function such that we only print to the granularity that the user wants.
Also, allow for formatting of sequential print statements ex: (10/114)
"""
global CHOSEN_VERBOSITY
if msgType <= CHOSEN_VERBOSITY:
out_file = sys.stdout if msgType > 1 else sys.stderr
if index is None or total is None:
print('{0}: {1}'.format(
LOG_VERBOSITIES[str(msgType)], msg), file=out_file)
else:
print('({0}/{1}) {2}: {3}'.format(index, total,
LOG_VERBOSITIES[str(msgType)], msg), file=out_file)
def requestUntilSuccess(
string: str,
invalid_msg: str = 'Invalid input',
validInput: Callable[[Any], bool] = lambda x: x is not None,
transformInput: Callable[[str], Any] = lambda x: x
) -> str:
"""
Requests user input until validInput predicate is satisfied.
Returns the output of transformInput.
"""
user_input = None
while not validInput(user_input):
print('=====================================')
user_input = input(string)
if not validInput(user_input):
print(invalid_msg)
return transformInput(user_input)
def login(session=requests.Session()):
"""
Logs in a user to the inputted session, and returns the session.
"""
global API_URL
user_input = requestUntilSuccess(
'Enter Target API (Default {0}): '.format(API_URL))
if user_input != '':
API_URL = user_input
# Get credentials
username = requestUntilSuccess(
'Enter credentials for {0}: '.format(API_URL))
logged_in = False
while not logged_in:
password = getpass.getpass("Password: ")
credentials = {
'email': username,
'password': password
}
r = session.post('{0}/api/auth/login'.format(API_URL), credentials)
if r.status_code != 200:
print("Incorrect password, please try again.")
else:
print('Logged in as {0}'.format(username))
logged_in = True
return session
def chooseLogVerbosity():
global CHOSEN_VERBOSITY
verbosity_list = ['{0}: {1}\n'.format(k, v)
for k, v in LOG_VERBOSITIES.items()]
chosen_verbosity = requestUntilSuccess(
'Input log verbosity (default {0}):\n{1}'.format(
CHOSEN_VERBOSITY, ''.join(verbosity_list)),
'Invalid verbosity',
lambda x: x == '' or x in LOG_VERBOSITIES.keys(),
lambda x: CHOSEN_VERBOSITY if x == '' else int(x)
)
CHOSEN_VERBOSITY = chosen_verbosity
def loadInvites() -> List[str]:
"""
Load the list of invites provided by user inputted file path.
"""
# Get information about batch actions
invite_file = requestUntilSuccess(
'Path to Invite CSV: ',
'Invalid file',
lambda x: x is not None and os.path.isfile(x) and os.access(x, os.R_OK)
)
invites = []
with open(invite_file, 'r') as csvfile:
reader = csv.DictReader(csvfile)
index = 1
for row in reader:
index = index + 1
email = row['email']
accountType = row['accountType']
if email is not None and accountType is not None:
invites.append({
'email': email,
'accountType': accountType
})
else:
_print('{2} is not a valid invite format'.format(
row), 1, index, len(reader))
return invites
def loadIDs() -> List[str]:
"""
Load the list of IDs provided by user inputted file path.
"""
# Get information about batch actions
id_file = requestUntilSuccess(
'Path to file to MongoIDs: ',
'Invalid file',
lambda x: x is not None and os.path.isfile(x) and os.access(x, os.R_OK)
)
ids = []
with open(id_file, 'r') as f:
rows = f.readlines()
for index, r in enumerate(rows):
index = index + 1
r = r.strip()
if ObjectId.is_valid(r):
ids.append(r)
else:
_print('{2} is not a valid ObjectID'.format(
r), 1, index, len(rows))
# remove duplicates
ids = list(set(ids))
return ids
def getDownloadDirectory() -> str:
directory = requestUntilSuccess(
'Directory to download files to: ',
'Invalid directory',
lambda x: x is not None and os.path.isdir(x) and os.access(x, os.W_OK)
)
directory.rstrip('/')
return directory
def status(prefixStr) -> str:
status_list = ['{0}: {1}\n'.format(k, v)
for k, v in VALID_STATUSES.items()]
initial_status = requestUntilSuccess(
'Input {0} status:\n{1}'.format(prefixStr, ''.join(status_list)),
'Invalid {0} status'.format(prefixStr),
lambda x: x in VALID_STATUSES.keys(),
lambda x: VALID_STATUSES[x]
)
return initial_status
def batchAction() -> str:
status_list = ['{0}: {1}\n'.format(k, v) for k, v in BATCH_ACTIONS.items()]
batch_action = requestUntilSuccess(
'Batch Action desired:\n{0}'.format(''.join(status_list)),
'Invalid batch action',
lambda x: x in BATCH_ACTIONS.keys(),
lambda x: BATCH_ACTIONS[x]
)
return batch_action
def reviewerStatus(prefixStr) -> str:
reviewerStatus_list = ['{0}: {1}\n'.format(k, v)
for k, v in VALID_REVIEWER_STATUSES.items()]
initial_reviewerStatus = requestUntilSuccess(
'Input {0} status:\n{1}'.format(prefixStr, ''.join(reviewerStatus_list)),
'Invalid {0} status'.format(prefixStr),
lambda x: x in VALID_REVIEWER_STATUSES.keys(),
lambda x: VALID_REVIEWER_STATUSES[x]
)
return initial_reviewerStatus
def reviewerStatus2(prefixStr) -> str:
reviewerStatus2_list = ['{0}: {1}\n'.format(k, v)
for k, v in VALID_REVIEWER_STATUSES.items()]
initial_reviewerStatus2 = requestUntilSuccess(
'Input {0} status:\n{1}'.format(prefixStr, ''.join(reviewerStatus2_list)),
'Invalid {0} status'.format(prefixStr),
lambda x: x in VALID_REVIEWER_STATUSES.keys(),
lambda x: VALID_REVIEWER_STATUSES[x]
)
return initial_reviewerStatus2
def reviewerName(prefixStr) -> str:
reviewerName_list = ['{0}: {1}\n'.format(k, v)
for k, v in str]
initial_reviewerName = requestUntilSuccess(
'Input {0} status:\n{1}'.format(prefixStr, ''.join(reviewerName_list)),
'Invalid {0} status'.format(prefixStr),
# lambda x: x in VALID_REVIEWER_STATUSES.keys(),
# lambda x: VALID_REVIEWER_STATUSES[x]
)
return initial_reviewerName
def reviewerName2(prefixStr) -> str:
reviewerName2_list = ['{0}: {1}\n'.format(k, v)
for k, v in str]
initial_reviewerName2 = requestUntilSuccess(
'Input {0} status:\n{1}'.format(prefixStr, ''.join(reviewerName2_list)),
'Invalid {0} status'.format(prefixStr),
# lambda x: x in VALID_REVIEWER_STATUSES.keys(),
# lambda x: VALID_REVIEWER_STATUSES[x]
)
return initial_reviewerName2
def reviewerComments(prefixStr) -> str:
reviewerComments_list = ['{0}: {1}\n'.format(k, v)
for k, v in str]
initial_reviewerComments = requestUntilSuccess(
'Input {0} status:\n{1}'.format(prefixStr, ''.join(reviewerComments_list)),
'Invalid {0} status'.format(prefixStr),
# lambda x: x in VALID_REVIEWER_STATUSES.keys(),
# lambda x: VALID_REVIEWER_STATUSES[x]
)
return initial_reviewerComments
def reviewerComments2(prefixStr) -> str:
reviewerComments2_list = ['{0}: {1}\n'.format(k, v)
for k, v in str]
initial_reviewerComments2 = requestUntilSuccess(
'Input {0} status:\n{1}'.format(prefixStr, ''.join(reviewerComments2_list)),
'Invalid {0} status'.format(prefixStr),
# lambda x: x in VALID_REVIEWER_STATUSES.keys(),
# lambda x: VALID_REVIEWER_STATUSES[x]
)
return initial_reviewerComments2
def getHacker(ID):
r = s.get('{0}/api/hacker/{1}'.format(API_URL, ID))
if r.status_code != 200:
return None
else:
hackerInfo = json.loads(r.content)['data']
return hackerInfo
def hasValidStatus(status, hackerInfo):
if hackerInfo is not None and hackerInfo['status'] == status:
return True
else:
return False
def hasValidReviewerStatus(reviewerStatus, hackerInfo):
if hackerInfo is not None and hackerInfo['reviewerStatus'] == reviewerStatus:
return True
else:
return False
def hasValidReviewerStatus2(reviewerStatus2, hackerInfo):
if hackerInfo is not None and hackerInfo['reviewerStatus2'] == reviewerStatus2:
return True
else:
return False
def hasValidReviewerName(reviewerName, hackerInfo):
if hackerInfo is not None and hackerInfo['reviewerName'] == reviewerName:
return True
else:
return False
def hasValidReviewerName2(reviewerName2, hackerInfo):
if hackerInfo is not None and hackerInfo['reviewerName2'] == reviewerName2:
return True
else:
return False
def hasValidReviewerComments(reviewerComments, hackerInfo):
if hackerInfo is not None and hackerInfo['reviewerComments'] == reviewerComments:
return True
else:
return False
def hasValidReviewerComments2(reviewerComments2, hackerInfo):
if hackerInfo is not None and hackerInfo['reviewerComments2'] == reviewerComments2:
return True
else:
return False
def search(model: str = 'hacker', query=[], expand: bool = True):
q = json.dumps(query)
expand = 'true' if expand else 'false'
r = s.get(
'{0}/api/search?model={1}&q={2}&expand={3}'.format(API_URL, model, q, expand))
if r.status_code != 200:
_print('Could not perform search (Status code {0})'.format(
r.status_code), 1)
return []
else:
results = json.loads(r.content)['data']
return results
def updateStatus():
INITIAL_STATUS = status('initial')
NEW_STATUS = status('new')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validStatus = hasValidStatus(INITIAL_STATUS, hacker)
if validStatus:
r = s.patch('{0}/api/hacker/status/{1}'.format(API_URL, ID),
{"status": NEW_STATUS})
if r.status_code != 200:
_print('cannot update status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('{0} {1}'.format(
NEW_STATUS, ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def updateReviewerStatus():
INITIAL_REVIEWER_STATUS = reviewerStatus('initial')
NEW_REVIEWER_STATUS = reviewerStatus('new')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validReviewerStatus = hasValidReviewerStatus(INITIAL_REVIEWER_STATUS, hacker)
if validReviewerStatus:
r = s.patch('{0}/api/hacker/reviewerStatus/{1}'.format(API_URL, ID),
{"reviewerStatus": NEW_REVIEWER_STATUS})
# if r.status_code != 200:
# _print('cannot update status for {0}'.format(
# ID), 1, index, len(HACKER_IDs))
# else:
_print('{0} {1}'.format(
NEW_REVIEWER_STATUS, ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def updateReviewerStatus2():
INITIAL_REVIEWER_STATUS2 = reviewerStatus2('initial')
NEW_REVIEWER_STATUS2 = reviewerStatus2('new')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validReviewerStatus2 = hasValidReviewerStatus2(INITIAL_REVIEWER_STATUS2, hacker)
if validReviewerStatus2:
r = s.patch('{0}/api/hacker/reviewerStatus2/{1}'.format(API_URL, ID),
{"reviewerStatus2": NEW_REVIEWER_STATUS2})
# if r.status_code != 200:
# _print('cannot update status for {0}'.format(
# ID), 1, index, len(HACKER_IDs))
# else:
_print('{0} {1}'.format(
NEW_REVIEWER_STATUS2, ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def updateReviewerName():
INITIAL_REVIEWER_NAME = reviewerName('initial')
NEW_REVIEWER_NAME = reviewerName('new')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validReviewerName = hasValidReviewerName(INITIAL_REVIEWER_NAME, hacker)
if validReviewerName:
r = s.patch('{0}/api/hacker/reviewerName/{1}'.format(API_URL, ID),
{"reviewerName": NEW_REVIEWER_NAME})
# if r.status_code != 200:
# _print('cannot update status for {0}'.format(
# ID), 1, index, len(HACKER_IDs))
# else:
_print('{0} {1}'.format(
NEW_REVIEWER_NAME, ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def updateReviewerName2():
INITIAL_REVIEWER_NAME2 = reviewerName2('initial')
NEW_REVIEWER_NAME2 = reviewerName2('new')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validReviewerName2 = hasValidReviewerName2(INITIAL_REVIEWER_NAME2, hacker)
if validReviewerName2:
r = s.patch('{0}/api/hacker/reviewerName2/{1}'.format(API_URL, ID),
{"reviewerName2": NEW_REVIEWER_NAME2})
# if r.status_code != 200:
# _print('cannot update status for {0}'.format(
# ID), 1, index, len(HACKER_IDs))
# else:
_print('{0} {1}'.format(
NEW_REVIEWER_NAME2, ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def updateReviewerComments():
INITIAL_REVIEWER_COMMENTS = reviewerComments('initial')
NEW_REVIEWER_COMMENTS = reviewerComments('new')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validReviewerComments = hasValidReviewerComments(INITIAL_REVIEWER_COMMENTS, hacker)
if validReviewerComments:
r = s.patch('{0}/api/hacker/reviewerComments/{1}'.format(API_URL, ID),
{"reviewerComments": NEW_REVIEWER_COMMENTS})
# if r.status_code != 200:
# _print('cannot update status for {0}'.format(
# ID), 1, index, len(HACKER_IDs))
# else:
_print('{0} {1}'.format(
NEW_REVIEWER_COMMENTS, ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def updateReviewerComments2():
INITIAL_REVIEWER_COMMENTS2 = reviewerComments2('initial')
NEW_REVIEWER_COMMENTS2 = reviewerComments2('new')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validReviewerComments2 = hasValidReviewerComments2(INITIAL_REVIEWER_COMMENTS2, hacker)
if validReviewerComments2:
r = s.patch('{0}/api/hacker/reviewerComments2/{1}'.format(API_URL, ID),
{"reviewerComments2": NEW_REVIEWER_COMMENTS2})
# if r.status_code != 200:
# _print('cannot update status for {0}'.format(
# ID), 1, index, len(HACKER_IDs))
# else:
_print('{0} {1}'.format(
NEW_REVIEWER_COMMENTS2, ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def sendDayOfEmail():
INITIAL_STATUS = status('initial')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validStatus = hasValidStatus(INITIAL_STATUS, hacker)
if validStatus:
r = s.post(
'{0}/api/hacker/email/dayOf/{1}'.format(API_URL, ID))
if r.status_code != 200:
_print('cannot send email to {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('Sent email to {0}'.format(
ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('Sent invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('Could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def sendWeekOfEmail():
INITIAL_STATUS = status('initial')
HACKER_IDs = loadIDs()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validStatus = hasValidStatus(INITIAL_STATUS, hacker)
if validStatus:
r = s.post(
'{0}/api/hacker/email/weekOf/{1}'.format(API_URL, ID))
if r.status_code != 200:
_print('Cannot send email to {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('Sent email to {0}'.format(
ID), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('Invalid status for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
_print('Could not find {0}'.format(
ID), 1, index, len(HACKER_IDs))
def downloadResume():
INITIAL_STATUS = status('initial')
HACKER_IDs = loadIDs()
DOWNLOAD_DIR = getDownloadDirectory()
for index, ID in enumerate(HACKER_IDs):
# so that we aren't 0-based index
index = index + 1
hacker = getHacker(ID)
validStatus = hasValidStatus(INITIAL_STATUS, hacker)
if validStatus:
r = s.get(
'{0}/api/hacker/resume/{1}'.format(API_URL, ID))
if r.status_code != 200:
_print('Could not find resume for {0}'.format(
ID), 1, index, len(HACKER_IDs))
else:
resume = json.loads(r.content)['data']['resume'][0]['data']
download_path = "{0}/{1}.pdf".format(DOWNLOAD_DIR, ID)
with open(download_path, "wb") as fh:
byte_data = bytearray(resume)
fh.write(byte_data)
_print('Downloaded resume for {0} to {1}'.format(
ID, download_path), 3, index, len(HACKER_IDs))
elif hacker is not None:
_print('invalid status for {0}'.format(
ID), 3, index, len(HACKER_IDs))
else:
_print('Could not find hacker {0}'.format(
ID), 1, index, len(HACKER_IDs))
def inviteUsers():
INVITES = loadInvites()
for index, invite in enumerate(INVITES):
index = index + 1
r = s.post(
'{0}/api/account/invite/'.format(API_URL), invite)
if r.status_code != 200:
_print('Could not invite {0}, {1}'.format(
invite['email'], invite['accountType']), 1, index, len(INVITES))
else:
_print('Invited {0}, {1}'.format(
invite['email'], invite['accountType']), 3, index, len(INVITES))
def getHackers():
CUR_STATUS = status('current')
DOWNLOAD_DIR = getDownloadDirectory()
results = search(
'hacker',
[{'param': 'status', 'operation': 'equals', 'value': CUR_STATUS}]
)
with open('{0}/hackerIDs_{1}.csv'.format(DOWNLOAD_DIR, CUR_STATUS), 'w') as out_file:
fieldnames = [
'id',
'First Name',
'Last Name',
'Email',
'School',
'Degree',
'Graduation Year',
'Job Interest',
'Github',
'LinkedIn'
]
csv_writer = csv.DictWriter(out_file, fieldnames=fieldnames)
csv_writer.writeheader()
for result in results:
csv_writer.writerow({
'id': result['id'],
'First Name': result['accountId']['firstName'],
'Last Name': result['accountId']['lastName'],
'Email': result['accountId']['email'],
'School': result['application']['general']['school'],
'Degree': result['application']['general']['degree'],
'Graduation Year': result['application']['general']['graduationYear'],
'Job Interest': result['application']['general']['jobInterest'],
'Github': result['application']['general']['URL']['github'],
'LinkedIn': result['application']['general']['URL']['linkedIn'],
})
if __name__ == "__main__":
# execute only if run as a script
chooseLogVerbosity()
login(s)
while True:
BATCH_ACTION = batchAction()
try:
if BATCH_ACTION == 'weekOf':
sendWeekOfEmail()
elif BATCH_ACTION == 'dayOf':
sendDayOfEmail()
elif BATCH_ACTION == 'updateStatus':
updateStatus()
elif BATCH_ACTION == 'downloadResume':
downloadResume()
elif BATCH_ACTION == 'inviteUsers':
inviteUsers()
elif BATCH_ACTION == 'getHackers':
getHackers()
elif BATCH_ACTION == 'updateReviewerStatus':
updateReviewerStatus()
elif BATCH_ACTION == 'updateReviewerStatus2':
updateReviewerStatus2()
elif BATCH_ACTION == 'updateReviewerName':
updateReviewerName()
elif BATCH_ACTION == 'updateReviewerName2':
updateReviewerName2()
elif BATCH_ACTION == 'updateReviewerComments':
updateReviewerComments()
elif BATCH_ACTION == 'updateReviewerComments2':
updateReviewerComments2()
print('Finished {0}'.format(BATCH_ACTION))
except Exception as e:
_print('Failed to perform action {0}: {1}'.format(
BATCH_ACTION, e), 1)