Skip to content

Commit 90d3dd2

Browse files
committed
v1.0.2 : Force color of entry, better log-in errors display
1 parent 70a6caa commit 90d3dd2

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

core.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
SCRIPT_NAME = 'CW Wizard'
1313

14-
VERSION = '1.0.1'
14+
VERSION = '1.0.2'
1515

1616
EXIT_ERROR_MSG = 'The Wizard encountered issue(s) please check previous logs.\n'
1717
EXIT_SUCCESS_MSG = 'The Wizard has finish is work, have a great day!\n'
@@ -67,7 +67,7 @@ def addError(self, message):
6767

6868
def addDetailedRequestError(self, task, response, as_warning=False):
6969
status_code = response.status_code
70-
message = 'Unable to {}. Request status code "{}":'.format(task, str(status_code))
70+
message = 'Unable to {}.\nRequest status code "{}":'.format(task, str(status_code))
7171

7272
# Check if we have more info on the request error
7373
status_code_info = REQUEST_ERRORS.get(status_code)
@@ -120,8 +120,9 @@ def logMessages(self):
120120
def getMessages(self, message_type='all'):
121121
messages = []
122122
for message in self.messages:
123-
if message_type != 'all' and message['type'] == message_type:
124-
messages.append(message)
123+
if message_type == 'all' or (message_type != 'all' and message['type'] == message_type):
124+
messages.append(message['content'])
125+
return messages
125126

126127
class ColoredFormatter(logging.Formatter):
127128
"""Custom formatter handling color"""
@@ -185,7 +186,12 @@ def cardmarket_log_in(session, credentials, silently=False):
185186
LOG.debug(' |____ No cookies will be stored/remains at the end.\n')
186187

187188
# Step 1: Get the login page html (to retrieve the login token)
188-
response_get_login_page = session.get(CARDMARKET_BASE_URL + '/Login')
189+
try:
190+
response_get_login_page = session.get(CARDMARKET_BASE_URL + '/Login')
191+
except Exception as e:
192+
funct_result.addError('Unable to connect to Cardmarket.\nReason: {}'.format(e))
193+
return funct_result
194+
189195
if response_get_login_page.status_code != 200:
190196
# Issue with the request
191197
funct_result.addDetailedRequestError('access to Cardmarket', response_get_login_page)
@@ -214,7 +220,7 @@ def cardmarket_log_in(session, credentials, silently=False):
214220
log_in_error_msg = extract_log_in_error_msg(response_post_login)
215221
if log_in_error_msg:
216222
# It's most likely an issue with the payload (wrong username and/or password)
217-
funct_result.addError('Unable to log-in to Cardmarket. Message: {}.'.format(log_in_error_msg))
223+
funct_result.addError('Unable to log-in to Cardmarket.\nMessage: {}.'.format(log_in_error_msg))
218224
return funct_result
219225

220226
if not silently:
@@ -590,7 +596,7 @@ def build_result_page(wantlists_info, max_sellers, sellers, relevant_sellers):
590596
# Step 4: Open the result page
591597
import webbrowser
592598
try:
593-
webbrowser.open(result_path.as_uri())
599+
webbrowser.open_new_tab(result_path.as_uri())
594600
except webbrowser.Error:
595601
# Since it's not critical at all only display a warning.
596602
funct_result.addWarning('Failed to automatically open the result page for you.')

cw-wizard-gui.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
THREAD_QUEUE = queue.Queue()
1818

19-
GUI_WINDOW_WIDTH = 500
19+
GUI_WINDOW_WIDTH = 600
2020
GUI_WINDOW_HEIGHT = 300
2121

22+
GUI_ENTRY_BORDER_WIDTH = 2
2223
GUI_ENTRY_BORDER_CLR = '#645c53'
2324

2425
GUI_FONT_LIST = ['Trebuchet MS', 'Helvetica', 'Lucida Sans', 'Tahoma', 'Arial']
@@ -88,7 +89,7 @@ def validate_entry_is_integer(new_value):
8889
return False
8990

9091
def create_entry(parent, variable, bg_color, password=False, width=0, int_only=False):
91-
entry = tkinter.Entry(parent, textvariable=variable, background=bg_color, highlightcolor=GUI_ENTRY_BORDER_CLR, highlightbackground=GUI_ENTRY_BORDER_CLR)
92+
entry = tkinter.Entry(parent, textvariable=variable, background=bg_color, foreground=GUI_FONT_STYLES['content']['font-color'], insertbackground=GUI_FONT_STYLES['content']['font-color'], highlightcolor=GUI_ENTRY_BORDER_CLR, highlightbackground=GUI_ENTRY_BORDER_CLR, highlightthickness=GUI_ENTRY_BORDER_WIDTH)
9293
if password:
9394
entry.configure(show='*')
9495
if width != 0:
@@ -179,7 +180,7 @@ def credentials_validity_has_finished(params):
179180

180181
if not result.isValid():
181182
# Couldn't connect, display error message
182-
window_request_credentials(params[0], 'Error: connection failed, ensure you enter the right credentials.')
183+
window_request_credentials(params[0], '\n'.join(result.getMessages(message_type='error')))
183184
return False
184185

185186
# Step 3: Store credentials dict in the window object
@@ -313,12 +314,12 @@ def window_request_credentials(window, error_msg=None):
313314
label_username = create_label(frame_credentials, 'Username', 'content', window.content_bg_color)
314315
label_username.grid(row=0, column=0, pady=(0, 4), sticky=tkinter.E)
315316
entry_username = create_entry(frame_credentials, username, window.content_bg_color)
316-
entry_username.grid(row=0, column=1, pady=(0, 4), sticky=tkinter.NSEW)
317+
entry_username.grid(row=0, column=1, ipadx=4, padx=(4, 0), pady=(0, 4), sticky=tkinter.NSEW)
317318

318319
label_password = create_label(frame_credentials, 'Password', 'content', window.content_bg_color)
319320
label_password.grid(row=1, column=0, sticky=tkinter.E)
320321
entry_password = create_entry(frame_credentials, password, window.content_bg_color, password=True)
321-
entry_password.grid(row=1, column=1, sticky=tkinter.NSEW)
322+
entry_password.grid(row=1, column=1, padx=(4, 0), sticky=tkinter.NSEW)
322323

323324
# Step 4: Add disclaimer message
324325
text_disclaimer = 'Disclaimer: If you have 2FA activate on your account this script won\'t work.'

0 commit comments

Comments
 (0)