Skip to content

Commit

Permalink
Better console logs to help user with problems
Browse files Browse the repository at this point in the history
  • Loading branch information
ariffjeff committed Jan 21, 2024
1 parent 54dbf8e commit 72dddee
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion reemployct_data_entry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import colorama

PACKAGE_NAME = 'reemployct_data_entry'

# can't use stdlib importlib.metadata here because remote tests will fail due to needing the package build
Expand All @@ -10,4 +12,4 @@
EXCEL_FILENAME = 'workSearch_template.xlsx'
excel_path = filepaths.dynamic_full_path(EXCEL_FILENAME, validate=True)

print('Job data Excel template: {}'.format(excel_path))
print(colorama.Fore.MAGENTA + f'\nJob data Excel template: {excel_path}' + colorama.Style.RESET_ALL)
4 changes: 2 additions & 2 deletions reemployct_data_entry/controller_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def are_work_search_correction_creds_set(self) -> bool:

def create_user_credentials():
''' Gets credentials for the DOL ReEmployCT portal from the user and saves them to the .ini creds file '''
print(colorama.Fore.GREEN + "\nEnter your DOL ReEmployCT credentials (encrypted and stored locally)..." + colorama.Style.RESET_ALL)
print(colorama.Fore.CYAN + "\nEnter your DOL ReEmployCT credentials (encrypted and stored locally)..." + colorama.Style.RESET_ALL)
creds = Credentials()
creds.rebuild_creds_from_file(filepaths.dynamic_full_path('credFile.ini'))

Expand Down Expand Up @@ -306,7 +306,7 @@ def create_correction_user_credentials():
https://ctdolcontactcenter.force.com/submit/s/claim-filing-and-payment
'''

print(colorama.Fore.GREEN + "\nEnter your DOL credentials (encrypted and stored locally)..." + colorama.Style.RESET_ALL)
print(colorama.Fore.CYAN + "\nEnter your DOL credentials (encrypted and stored locally)..." + colorama.Style.RESET_ALL)
creds = Credentials()
creds.rebuild_creds_from_file(filepaths.dynamic_full_path('credFile.ini'))

Expand Down
8 changes: 4 additions & 4 deletions reemployct_data_entry/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
if(not filepaths.is_filepath_valid(JOB_FILEPATH_JSON)):
with open(JOB_FILEPATH_JSON, 'w') as file:
json.dump({'filepath_jobData': ''}, file)
print("Created: {}".format(JOB_FILEPATH_JSON))
print(colorama.Fore.GREEN + f"Created: {JOB_FILEPATH_JSON}" + colorama.Style.RESET_ALL)

# get job data filepath from json
with open(JOB_FILEPATH_JSON, 'r') as file:
Expand All @@ -34,7 +34,7 @@ def main():
# validate job data filepath
updateJobFilepath = False
while(not filepaths.is_job_data_filepath_valid(json_jobDataFilepath['filepath_jobData'])):
json_jobDataFilepath['filepath_jobData'] = input(colorama.Fore.GREEN + "Enter the full filepath (including file extension) of your job data excel file: " + colorama.Style.RESET_ALL)
json_jobDataFilepath['filepath_jobData'] = input(colorama.Fore.CYAN + "Enter the full filepath (including file extension) of your job data excel file: " + colorama.Style.RESET_ALL)
updateJobFilepath = True

# set json job data filepath in jobDataLocation.json
Expand All @@ -52,10 +52,10 @@ def main():
KEY_KEY = filepaths.dynamic_full_path('key.key')
if(not os.path.exists(CRED_FILE) or not os.path.exists(KEY_KEY)):
if(os.path.exists(CRED_FILE)):
print("Missing credential's key file.\nDeleting credentials file to reset.")
print(colorama.Fore.YELLOW + "Missing credential's key file. Deleting credentials file to reset." + colorama.Style.RESET_ALL)
os.remove(CRED_FILE)
elif(os.path.exists(KEY_KEY)):
print("Missing credentials file.\nDeleting credential's key file to reset.")
print(colorama.Fore.YELLOW + "Missing credentials file. Deleting credential's key file to reset.")
os.remove(KEY_KEY)
credCon.create_user_credentials()

Expand Down
12 changes: 7 additions & 5 deletions reemployct_data_entry/lib/filepaths.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import os
import inspect

import colorama


def is_job_data_filepath_valid(filepath):
if(not os.path.isfile(filepath) or os.path.splitext(filepath)[-1] != ".xlsx"):
if(len(filepath) == 0): # mainly for when initial package gets installed and there is no path set
print("No user job data excel file found.")
print(colorama.Fore.YELLOW + "No user job data excel file found." + colorama.Style.RESET_ALL)
return False
print("No user job data excel file found: {}".format(filepath))
print(colorama.Fore.YELLOW + f"No user job data excel file found: {filepath}" + colorama.Style.RESET_ALL)
return False
print("User job data excel file found: {}".format(filepath))
print(colorama.Fore.GREEN + f"Using user job data from Excel file: {filepath}" + colorama.Style.RESET_ALL)
return True

def is_filepath_valid(filepath):
if(not os.path.isfile(filepath)):
print("No user job data .json config found: {}".format(filepath))
print(colorama.Fore.YELLOW + f"No user job data .json config found: {filepath}" + colorama.Style.RESET_ALL)
return False
print("User job data config found: {}".format(filepath))
print(colorama.Fore.GREEN + f"Using user job data config: {filepath}" + colorama.Style.RESET_ALL)
return True

def dynamic_full_path(filename, validate=False) -> str:
Expand Down
8 changes: 5 additions & 3 deletions reemployct_data_entry/lib/job_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ def target_week_has_jobs(self) -> bool:
'''

if(len(self.jobs) == 0):
print(colorama.Fore.RED +
f"\n*** You have no days of job data to enter for the target week! ({self.week.start.date()} - {self.week.end.date()}) ***\nQuitting script."
+ colorama.Style.RESET_ALL)
print(colorama.Fore.RED + f"\n***\nYou have no valid days (rows) of job data from your Excel file to enter for the target week! ({self.week.start.date()} - {self.week.end.date()})")
print("If applicable, make sure that:")
print(" 1. jobDataLocation.json is using the correct Excel file that contains your job data.")
print(" 2. All the job data for the week is formatted correctly in the Excel file.")
print("Fix any issues and try again. Quitting script.\n***"+ colorama.Style.RESET_ALL)
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion reemployct_data_entry/lib/wrangle_job_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_existing_entries(driver: webdriver.Firefox, silent=False) -> dict:
'\n{} existing work entries found. Minimum requirements already met.'.format(entries_existing_n)
+ colorama.Style.RESET_ALL)
else:
print(colorama.Fore.GREEN +
print(colorama.Fore.YELLOW +
'\n{} existing work entries found. Must enter {} more for DOL compliance.'.format(entries_existing_n, entries_min - entries_existing_n)
+ colorama.Style.RESET_ALL)

Expand Down

0 comments on commit 72dddee

Please sign in to comment.