Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handeling and code optimization #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Check whether the scriptname exist in the argument or not
if len(sys.argv) < 2:
print('Script Name is missing: Try \'python3 bot.py scriptname\'')
print(f"Script Name is missing: Try 'python3 bot.py scriptname'")

else:
if sys.argv[1] == 'template_subs':
Expand Down
8 changes: 5 additions & 3 deletions botscripts/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def get_crsf_token(self):
data = response.json()
try:
return data['query']['tokens']['csrftoken']
except:
return None
except KeyError:
print("Error: CSRF token not found in the response.")
return None

def get_pagecontent(self, page):
""" Function to get the wikitext of Wikipage """
Expand All @@ -43,7 +44,8 @@ def get_pagecontent(self, page):
else:
print('\n' + page + ' - ' + data['error']['info'])
return None
except:
except KeyError:
print(f"Error: Unexpected response format for page '{page}'.")
return None


Expand Down
2 changes: 1 addition & 1 deletion botscripts/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def login():
data = response.json()

if data['clientlogin']['status'] == 'PASS':
print('Login success! Welcome, ' + data['clientlogin']['username'] + '!')
print(f'Login success! Welcome, {data["clientlogin"]["username"]}!')
return Ses
else:
print('Oops! Something went wrong -- ' + data['clientlogin']['messagecode'])
Expand Down
2 changes: 1 addition & 1 deletion scripts/template_subs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run_template_subs(session):
if oldtext != text:

# Make and print the diff
print('\nDiff of Wikipage - ' + wikipage)
print(f"\nDiff of Wikipage - {wikipage}")
diff(oldtext, text)

if apply_all is False:
Expand Down