Skip to content

Commit

Permalink
Code Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sliicy committed Aug 2, 2020
1 parent 3299b9e commit 2b949b3
Showing 1 changed file with 40 additions and 39 deletions.
79 changes: 40 additions & 39 deletions eruv_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def army_to_meridian(input_time):
'--available-cities',
action='store_true',
help='Return a list of all available cities.')
parser.add_argument(
'--blacklist',
nargs='+',
help='Append a list of cities (space delimited) to skip alerting (cities with 2+ names should be enclosed in quotes). Available cities can be found using the --available-cities flag. This argument will override the whitelist argument.')
parser.add_argument(
'--custom-message',
action='append',
Expand All @@ -106,14 +110,6 @@ def army_to_meridian(input_time):
'--donate',
action='store_true',
help='Append a reminder to donate for select cities.')
parser.add_argument(
'--blacklist',
nargs='+',
help='Append a list of cities (space delimited) to skip alerting (cities with 2+ names should be enclosed in quotes). Available cities can be found using the --available-cities flag. This argument will override the whitelist argument.')
parser.add_argument(
'--whitelist',
nargs='+',
help='Append a list of cities (space delimited) to only alert (cities with 2+ names should be enclosed in quotes). All other cities will be skipped. Available cities can be found using the --available-cities flag. The blacklist argument will override this.')
parser.add_argument(
'--no-candlelighting',
action='store_true',
Expand All @@ -126,10 +122,6 @@ def army_to_meridian(input_time):
'--no-weather',
action='store_true',
help='Skip checking for and reporting any weather updates. This will override the force-weather argument.')
parser.add_argument(
'--weather',
action='store_true',
help='Adds the weather to be reported and warn recipients.')
parser.add_argument(
'--test',
action='store_true',
Expand All @@ -139,39 +131,49 @@ def army_to_meridian(input_time):
'--verbose',
action='store_true',
help='Verbose output. Useful for debugging.')
parser.add_argument(
'--weather',
action='store_true',
help='Adds the weather to be reported and warn recipients.')
parser.add_argument(
'--whitelist',
nargs='+',
help='Append a list of cities (space delimited) to only alert (cities with 2+ names should be enclosed in quotes). All other cities will be skipped. Available cities can be found using the --available-cities flag. The blacklist argument will override this.')
argcomplete.autocomplete(parser)
arguments = parser.parse_args()

# Display test mode warning:
if arguments.test:
print('Test mode is on. Nothing will actually be sent.\n')

# Display ignored cities:
if arguments.blacklist and arguments.verbose and not arguments.whitelist:
print('Cities that will be skipped: ' +
str([x.title() for x in arguments.blacklist]) + '\n')
# Dispaly additional information if verbose requested:
if arguments.verbose:

# Display whitelisted cities:
if arguments.whitelist and arguments.verbose:
if arguments.blacklist:
print('Only these cities will be notified: ' +
str(list(set([x.title() for x in arguments.whitelist]) -
set([x.title() for x in arguments.blacklist]))) +
'\n')
else:
print('Only these cities will be notified: ' +
str([x.title() for x in arguments.whitelist]) + '\n')
# Display ignored cities:
if arguments.blacklist and not arguments.whitelist:
print('Cities that will be skipped: ' +
str([x.title() for x in arguments.blacklist]) + '\n')

# Display custom message:
if arguments.custom_message and arguments.verbose:
if arguments.append:
print('A custom & appended message will be sent out instead!\n')
else:
print('A custom message will be sent out instead!\n')
# Display whitelisted cities:
if arguments.whitelist:
if arguments.blacklist:
print('Only these cities will be notified: ' +
str(list(set([x.title() for x in arguments.whitelist]) -
set([x.title() for x in arguments.blacklist]))) + '\n')
else:
print('Only these cities will be notified: ' +
str([x.title() for x in arguments.whitelist]) + '\n')

# Display appended message:
if arguments.append and arguments.verbose and not arguments.custom_message:
print('An appended message will be sent out along with the regular message!\n')
# Display custom message:
if arguments.custom_message:
if arguments.append:
print('A custom & appended message will be sent out instead!\n')
else:
print('A custom message will be sent out instead!\n')

# Display appended message:
if arguments.append and not arguments.custom_message:
print('An appended message will be sent out along with the regular message!\n')

# Google Authentication from external JSON file:
scope = ['https://spreadsheets.google.com/feeds',
Expand Down Expand Up @@ -401,14 +403,14 @@ def army_to_meridian(input_time):
# Keep track of total # of users:
population += 1
user_index += 1

if arguments.custom_message:
print('\n' +
str(population) +
' users ' +
('would have been ' if arguments.test else '') +
'notified: ' +
message +
'.\n')
message + '.\n')
else:
print('\n' +
str(population) +
Expand All @@ -417,6 +419,5 @@ def army_to_meridian(input_time):
'notified that ' +
city +
' is ' +
city_statuses[city_index] +
'.\n')
city_statuses[city_index] + '.\n')
city_index += 1

0 comments on commit 2b949b3

Please sign in to comment.