Skip to content

Commit 5f2b6aa

Browse files
Update 1.4.5
- fixed a memory leak when switching from main menu and voting mode many times
1 parent 203c1fb commit 5f2b6aa

2 files changed

Lines changed: 81 additions & 88 deletions

File tree

main.py

Lines changed: 80 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -13,111 +13,104 @@
1313

1414

1515
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)
1920

20-
unvoted_theme_count = len(themes) - len(user_votes)
21+
unvoted_theme_count = len(themes) - len(user_votes)
2122

22-
# default valid selections
23-
valid_selections = ['1', '2', '3']
23+
# default valid selections
24+
valid_selections = ['1', '2', '3']
2425

25-
clear_console()
26+
clear_console()
2627

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()
3031

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')
3233

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
3839

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')
4142

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')
4849

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')
5354

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')
5857

59-
# get user selection
60-
selection = input('Selection > ')
58+
print()
6159

62-
# make sure selection is valid
63-
while selection not in valid_selections:
64-
print('Invalid selection. Try again.')
60+
# get user selection
6561
selection = input('Selection > ')
6662

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!')
86107
exit(0)
87108

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)
109112
exit(0)
110113

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-
121114

122115
def cookie_setup():
123116
# try to load cookies automatically

util/CONSTANTS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
CONFIG_FILE = 'config.yml'
2-
VERSION = '1.4.4'
2+
VERSION = '1.4.5'
33
AUTHOR = 'InitialPosition / RedCocoa'

0 commit comments

Comments
 (0)