11import json
2+ from os import remove
23from os .path import isfile
34
45from termcolor import cprint
@@ -43,7 +44,8 @@ def main_menu():
4344 # if an update is available, say so and enable option to download update
4445 if update_check_result == UpdateCheckResult .UPDATE_AVAILABLE :
4546 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+ f'Changelog: https://github.com/InitialPosition/pyJAMa/releases/tag/v{ new_update_version } \n ' ,
48+ 'white' ,
4749 'on_green' )
4850 valid_selections .append ('4' )
4951
@@ -74,11 +76,13 @@ def main_menu():
7476 # voting failed for some reason. abort and tell the user
7577 clear_console ()
7678
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' )
79+ cprint (
80+ 'An error occurred during the voting process. This probably means the API is overloaded or you lost '
81+ 'internet connection.' ,
82+ 'red' )
83+ cprint (
84+ 'The program will now terminate. Check your internet connection and try again. If voting still fails'
85+ ', wait a few minutes and try again.' , 'red' )
8286
8387 exit (0 )
8488
@@ -119,6 +123,7 @@ def cookie_setup():
119123 if cookie_fetch != - 1 :
120124 print (f'Cookie retrieved: { cookie_fetch } ' )
121125 save_config (cookie_fetch )
126+
122127 return
123128
124129 clear_console ()
@@ -177,9 +182,39 @@ def cookie_setup():
177182jsonified_themes = json .loads (request .text )
178183
179184if jsonified_themes ['status' ] == 200 :
185+ if isfile ('cookie_fail' ):
186+ remove ('cookie_fail' )
187+
180188 themes = jsonified_themes ["ideas" ]
181189else :
182190
191+ if isfile ('cookie_fail' ):
192+ remove ('cookie_fail' )
193+
194+ clear_console ()
195+
196+ # print logo
197+ print_file ('files/logo.txt' )
198+ print_version_info ()
199+ print ()
200+
201+ # explain why cookies are necessary
202+ print_file ('files/cookie_explanation.txt' )
203+ print ()
204+
205+ # get cookie input
206+ cookie_sids = input ('SIDS > ' )
207+
208+ # treat empty input as deletion request, otherwise save new data
209+ if cookie_sids == '' :
210+ delete_config ()
211+ exit (0 )
212+ else :
213+ save_config (cookie_sids )
214+
215+ print ('\n Cookie saved. Please restart the program.' )
216+ exit (0 )
217+
183218 # if we land here, the API was not happy with our theme request, meaning something is most likely wrong with the
184219 # entered cookies. we delete the cookies and let the user enter them again.
185220 clear_console ()
@@ -190,13 +225,18 @@ def cookie_setup():
190225 'red' )
191226 cprint ('If you are, you might want to log out and back in once.' ,
192227 'red' )
228+ cprint ('If cookie fetching isn\' t successful next time, you will be required to enter your token manually.' ,
229+ 'red' )
193230
194231 print ()
195232 print ('DEBUG INFO:' )
196233 print (jsonified_themes )
197234 print ()
198235
199236 delete_config ()
237+ with open ('cookie_fail' , 'w' ) as f :
238+ f .write ('If this file exists, a saved cookie was no longer valid for the API. If a new cookie can\' t be '
239+ 'fetched next time the program runs, it will ask you for manual cookie entry.\n ' )
200240
201241 exit (0 )
202242
0 commit comments