|
8 | 8 |
|
9 | 9 |
|
10 | 10 | def get_cookie_header(): |
11 | | - # load data from local config |
12 | | - cookie_data = load_config() |
| 11 | + # load data from local config |
| 12 | + cookie_data = load_config() |
13 | 13 |
|
14 | | - cookie1 = cookie_data.get('SIDS') |
| 14 | + cookie1 = cookie_data.get('SIDS') |
15 | 15 |
|
16 | | - # build header in correct format |
17 | | - header = {'Cookie': f'SIDS={cookie1}'} |
| 16 | + # build header in correct format |
| 17 | + header = {'Cookie': f'SIDS={cookie1}'} |
18 | 18 |
|
19 | | - return header |
| 19 | + return header |
20 | 20 |
|
21 | 21 |
|
22 | 22 | def get_event_themes(event_id: int): |
23 | | - # call ldjam API to get all running events themes |
24 | | - header = get_cookie_header() |
25 | | - call_url = f'https://api.ldjam.com/vx/theme/idea/vote/get/{event_id}' |
| 23 | + # call ldjam API to get all running events themes |
| 24 | + header = get_cookie_header() |
| 25 | + call_url = f'https://api.ldjam.com/vx/theme/idea/vote/get/{event_id}' |
26 | 26 |
|
27 | | - request = get(call_url, headers=header) |
| 27 | + request = get(call_url, headers=header) |
28 | 28 |
|
29 | | - return request |
| 29 | + return request |
30 | 30 |
|
31 | 31 |
|
32 | 32 | def get_current_event_id(): |
33 | | - # call ldjam API to get running events ID (this call doesnt need auth headers) |
34 | | - call_url = 'https://api.ldjam.com/vx/node2/what/1' |
35 | | - request = get(call_url) |
| 33 | + # call ldjam API to get running events ID (this call doesnt need auth headers) |
| 34 | + call_url = 'https://api.ldjam.com/vx/node2/what/1' |
| 35 | + request = get(call_url) |
36 | 36 |
|
37 | | - request_json = json.loads(request.text) |
| 37 | + request_json = json.loads(request.text) |
38 | 38 |
|
39 | | - # if we got an answer, extract event ID and return, otherwise abort |
40 | | - if request_json['status'] == 200: |
41 | | - event_id = request_json.get('featured').get('id') |
| 39 | + # if we got an answer, extract event ID and return, otherwise abort |
| 40 | + if request_json['status'] == 200: |
| 41 | + event_id = request_json.get('featured').get('id') |
42 | 42 |
|
43 | | - print(f'done. ID: {event_id}') |
44 | | - return event_id |
45 | | - else: |
46 | | - print('ERROR! Could not fetch current LDJAM ID. Aborting...') |
47 | | - exit(0) |
| 43 | + print(f'done. ID: {event_id}') |
| 44 | + return event_id |
| 45 | + else: |
| 46 | + print('ERROR! Could not fetch current LDJAM ID. Aborting...') |
| 47 | + exit(0) |
48 | 48 |
|
49 | 49 |
|
50 | 50 | def get_user_votes(event_id: int): |
51 | | - # call ldjam API to get all themes the user already voted on |
52 | | - header = get_cookie_header() |
53 | | - call_url = f'https://api.ldjam.com/vx/theme/idea/vote/getmy/{event_id}' |
| 51 | + # call ldjam API to get all themes the user already voted on |
| 52 | + header = get_cookie_header() |
| 53 | + call_url = f'https://api.ldjam.com/vx/theme/idea/vote/getmy/{event_id}' |
54 | 54 |
|
55 | | - request = get(call_url, headers=header) |
| 55 | + request = get(call_url, headers=header) |
56 | 56 |
|
57 | | - request_json = json.loads(request.text) |
| 57 | + request_json = json.loads(request.text) |
58 | 58 |
|
59 | | - # if we got an answer, extract voted themes and return, otherwise abort |
60 | | - if request_json['status'] == 200: |
61 | | - user_votes = request_json.get('votes') |
| 59 | + # if we got an answer, extract voted themes and return, otherwise abort |
| 60 | + if request_json['status'] == 200: |
| 61 | + user_votes = request_json.get('votes') |
62 | 62 |
|
63 | | - return user_votes |
64 | | - else: |
65 | | - try: |
66 | | - if request_json['message'] == 'Event is not Slaughtering': |
67 | | - print('Theme slaughter has not begun yet! Please try again later.') |
68 | | - exit(0) |
| 63 | + return user_votes |
| 64 | + else: |
| 65 | + try: |
| 66 | + if request_json['message'] == 'Event is not Slaughtering': |
| 67 | + print('Theme slaughter has not begun yet! Please try again later.') |
| 68 | + exit(0) |
69 | 69 |
|
70 | | - except KeyError: |
71 | | - print('ERROR! Could not fetch user votes. Aborting...') |
72 | | - exit(0) |
| 70 | + except KeyError: |
| 71 | + print('ERROR! Could not fetch user votes. Aborting...') |
| 72 | + exit(0) |
73 | 73 |
|
74 | | - print('ERROR! Could not fetch user votes. Aborting...') |
75 | | - exit(0) |
| 74 | + print('ERROR! Could not fetch user votes. Aborting...') |
| 75 | + exit(0) |
76 | 76 |
|
77 | 77 |
|
78 | 78 | def vote_theme(theme_id: int, voting: str): |
79 | | - # call ldjam API to vote on given theme ID with the given voting string |
80 | | - header = get_cookie_header() |
| 79 | + # call ldjam API to vote on given theme ID with the given voting string |
81 | 80 |
|
82 | | - try: |
83 | | - request = get(f'https://api.ldjam.com/vx/theme/idea/vote/{voting}/{theme_id}', headers=header) |
| 81 | + header = get_cookie_header() |
84 | 82 |
|
85 | | - except RequestConnectionError: |
86 | | - return -1 |
87 | | - except NewConnectionError: |
88 | | - return -1 |
| 83 | + try: |
| 84 | + request = get(f'https://api.ldjam.com/vx/theme/idea/vote/{voting}/{theme_id}', headers=header) |
89 | 85 |
|
90 | | - request_json = json.loads(request.text) |
| 86 | + except RequestConnectionError: |
| 87 | + return -1 |
| 88 | + except NewConnectionError: |
| 89 | + return -1 |
91 | 90 |
|
92 | | - # return whether vote was successful |
93 | | - if request_json['status'] == 200: |
94 | | - return 0 |
| 91 | + request_json = json.loads(request.text) |
95 | 92 |
|
96 | | - return -1 |
| 93 | + # return whether vote was successful |
| 94 | + if request_json['status'] == 200: |
| 95 | + return 0 |
| 96 | + |
| 97 | + return -1 |
0 commit comments