|
13 | 13 |
|
14 | 14 |
|
15 | 15 | def main_menu(): |
16 | | - # update user votes and counts on return to main menu |
17 | | - print('Fetching user votes...') |
18 | | - user_votes = get_user_votes(event_id) |
| 16 | + while True: |
| 17 | + # update user votes and counts on return to main menu |
| 18 | + print('Fetching user votes...') |
| 19 | + user_votes = get_user_votes(event_id) |
19 | 20 |
|
20 | | - unvoted_theme_count = len(themes) - len(user_votes) |
| 21 | + unvoted_theme_count = len(themes) - len(user_votes) |
21 | 22 |
|
22 | | - # default valid selections |
23 | | - valid_selections = ['1', '2', '3'] |
| 23 | + # default valid selections |
| 24 | + valid_selections = ['1', '2', '3'] |
24 | 25 |
|
25 | | - clear_console() |
| 26 | + clear_console() |
26 | 27 |
|
27 | | - # print logo and info |
28 | | - print_file('files/logo.txt') |
29 | | - print_version_info() |
| 28 | + # print logo and info |
| 29 | + print_file('files/logo.txt') |
| 30 | + print_version_info() |
30 | 31 |
|
31 | | - print(f'\n{len(themes)} themes loaded.\nUnvoted themes: {max(0, unvoted_theme_count)}\n') |
| 32 | + print(f'\n{len(themes)} themes loaded.\nUnvoted themes: {max(0, unvoted_theme_count)}\n') |
32 | 33 |
|
33 | | - # TODO implement proper final round voting |
34 | | - if unvoted_theme_count < 0: |
35 | | - # disable voting selections |
36 | | - valid_selections.pop(0) |
37 | | - valid_selections.pop(0) # pop 0 again since every index moves once during first pop |
| 34 | + # TODO implement proper final round voting |
| 35 | + if unvoted_theme_count < 0: |
| 36 | + # disable voting selections |
| 37 | + valid_selections.pop(0) |
| 38 | + valid_selections.pop(0) # pop 0 again since every index moves once during first pop |
38 | 39 |
|
39 | | - # print explanation |
40 | | - print('This script currently does not support final theme voting rounds.\n') |
| 40 | + # print explanation |
| 41 | + print('This script currently does not support final theme voting rounds.\n') |
41 | 42 |
|
42 | | - # if an update is available, say so and enable option to download update |
43 | | - if update_check_result == UpdateCheckResult.UPDATE_AVAILABLE: |
44 | | - cprint(f'NEW VERSION AVAILABLE: {new_update_version}\n' |
45 | | - f'Changelog: https://github.com/InitialPosition/pyJAMa/releases/tag/v{new_update_version}\n', 'white', |
46 | | - 'on_green') |
47 | | - valid_selections.append('4') |
| 43 | + # if an update is available, say so and enable option to download update |
| 44 | + if update_check_result == UpdateCheckResult.UPDATE_AVAILABLE: |
| 45 | + cprint(f'NEW VERSION AVAILABLE: {new_update_version}\n' |
| 46 | + f'Changelog: https://github.com/InitialPosition/pyJAMa/releases/tag/v{new_update_version}\n', 'white', |
| 47 | + 'on_green') |
| 48 | + valid_selections.append('4') |
48 | 49 |
|
49 | | - # print default main menu |
50 | | - print('[1] Start list theme voting') |
51 | | - print('[2] Start keyword theme voting') |
52 | | - print('[3] Exit') |
| 50 | + # print default main menu |
| 51 | + print('[1] Start list theme voting') |
| 52 | + print('[2] Start keyword theme voting') |
| 53 | + print('[3] Exit') |
53 | 54 |
|
54 | | - if update_check_result == UpdateCheckResult.UPDATE_AVAILABLE: |
55 | | - print('[4] Download Update') |
56 | | - |
57 | | - print() |
| 55 | + if update_check_result == UpdateCheckResult.UPDATE_AVAILABLE: |
| 56 | + print('[4] Download Update') |
58 | 57 |
|
59 | | - # get user selection |
60 | | - selection = input('Selection > ') |
| 58 | + print() |
61 | 59 |
|
62 | | - # make sure selection is valid |
63 | | - while selection not in valid_selections: |
64 | | - print('Invalid selection. Try again.') |
| 60 | + # get user selection |
65 | 61 | selection = input('Selection > ') |
66 | 62 |
|
67 | | - # start normal voting mode |
68 | | - if selection == '1': |
69 | | - voting_result = start_general_voting(themes, user_votes) |
70 | | - |
71 | | - # reopen main menu if user typed c or no themes are left |
72 | | - if voting_result == VotingExitReason.USER_ABORTED or voting_result == VotingExitReason.NO_MORE_THEMES: |
73 | | - main_menu() |
74 | | - |
75 | | - # handle error |
76 | | - if voting_result == VotingExitReason.GENERAL_ERROR: |
77 | | - # voting failed for some reason. abort and tell the user |
78 | | - clear_console() |
79 | | - |
80 | | - cprint('An error occurred during the voting process. This probably means the API is overloaded or you lost ' |
81 | | - 'internet connection.', |
82 | | - 'red') |
83 | | - cprint('The program will now terminate. Check your internet connection and try again. If voting still fails' |
84 | | - ', wait a few minutes and try again.', 'red') |
85 | | - |
| 63 | + # make sure selection is valid |
| 64 | + while selection not in valid_selections: |
| 65 | + print('Invalid selection. Try again.') |
| 66 | + selection = input('Selection > ') |
| 67 | + |
| 68 | + # start normal voting mode |
| 69 | + if selection == '1': |
| 70 | + voting_result = start_general_voting(themes, user_votes) |
| 71 | + |
| 72 | + # handle error |
| 73 | + if voting_result == VotingExitReason.GENERAL_ERROR: |
| 74 | + # voting failed for some reason. abort and tell the user |
| 75 | + clear_console() |
| 76 | + |
| 77 | + cprint('An error occurred during the voting process. This probably means the API is overloaded or you lost ' |
| 78 | + 'internet connection.', |
| 79 | + 'red') |
| 80 | + cprint('The program will now terminate. Check your internet connection and try again. If voting still fails' |
| 81 | + ', wait a few minutes and try again.', 'red') |
| 82 | + |
| 83 | + exit(0) |
| 84 | + |
| 85 | + # start bulk voting mode |
| 86 | + if selection == '2': |
| 87 | + voting_result = start_bulk_voting(themes, user_votes) |
| 88 | + |
| 89 | + # handle error |
| 90 | + if voting_result == VotingExitReason.GENERAL_ERROR: |
| 91 | + # voting failed for some reason. abort and tell the user |
| 92 | + clear_console() |
| 93 | + |
| 94 | + cprint( |
| 95 | + 'An error occurred during the voting process. This probably means the API is overloaded or you lost ' |
| 96 | + 'internet connection.', |
| 97 | + 'red') |
| 98 | + cprint( |
| 99 | + 'The program will now terminate. Check your internet connection and try again. If voting still fails' |
| 100 | + ', wait a few minutes and try again.', 'red') |
| 101 | + |
| 102 | + exit(0) |
| 103 | + |
| 104 | + # exit program |
| 105 | + if selection == '3': |
| 106 | + print('Goodbye. Keep jamming!') |
86 | 107 | exit(0) |
87 | 108 |
|
88 | | - # start bulk voting mode |
89 | | - if selection == '2': |
90 | | - voting_result = start_bulk_voting(themes, user_votes) |
91 | | - |
92 | | - # reopen main menu if user typed c or no themes are left |
93 | | - if voting_result == VotingExitReason.USER_ABORTED or voting_result == VotingExitReason.NO_MORE_THEMES: |
94 | | - main_menu() |
95 | | - |
96 | | - # handle error |
97 | | - if voting_result == VotingExitReason.GENERAL_ERROR: |
98 | | - # voting failed for some reason. abort and tell the user |
99 | | - clear_console() |
100 | | - |
101 | | - cprint( |
102 | | - 'An error occurred during the voting process. This probably means the API is overloaded or you lost ' |
103 | | - 'internet connection.', |
104 | | - 'red') |
105 | | - cprint( |
106 | | - 'The program will now terminate. Check your internet connection and try again. If voting still fails' |
107 | | - ', wait a few minutes and try again.', 'red') |
108 | | - |
| 109 | + # download and apply update (this is only accessible if an update is actually available) |
| 110 | + if selection == '4': |
| 111 | + download_update(new_update_version) |
109 | 112 | exit(0) |
110 | 113 |
|
111 | | - # exit program |
112 | | - if selection == '3': |
113 | | - print('Goodbye. Keep jamming!') |
114 | | - exit(0) |
115 | | - |
116 | | - # download and apply update (this is only accessible if an update is actually available) |
117 | | - if selection == '4': |
118 | | - download_update(new_update_version) |
119 | | - exit(0) |
120 | | - |
121 | 114 |
|
122 | 115 | def cookie_setup(): |
123 | 116 | # try to load cookies automatically |
|
0 commit comments