This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (39 loc) · 1.54 KB
/
main.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
from typing import List
from src import orcicorn_client, shift_code_client, user_builder
from src.gcloud_storage import GCloudStorage
from src.slack_client import SlackClient
from src.user_builder import User
def redeem_codes(users: List[User], codes: List[str]):
slack_client = SlackClient()
for code in codes:
print(code)
slack_client.send_code_to_slack(code)
submission_status = {
'success': [],
'failure': []
}
for user in users:
try:
shift_code_client.ShiftCodeClient(user, code).submit_shift_code()
submission_status['success'].append(user.name)
except Exception as e:
print(e)
submission_status['failure'].append(user.name)
slack_client.send_redemptions_to_slack(submission_status['success'], submission_status['failure'])
def get_codes(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values that can be turned into a
Response object using
`make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
"""
storage_class = GCloudStorage()
codes = orcicorn_client.get_new_codes(storage_class)
if codes:
users = user_builder.build_users(storage_class)
redeem_codes(users, codes)
return f'Found {len(codes)} code to submit. Check slack and shift for results!'
if __name__ == '__main__':
get_codes(None)