Permalink
Browse files

fix(aws): make env vars for aws keys optional

  • Loading branch information...
philbooth committed Aug 14, 2018
1 parent 6c4ed5b commit f0f27d72ba0d799bf6f59d73410d4195a3cb6261
Showing with 6 additions and 5 deletions.
  1. +6 −5 forecast_sms.py
@@ -13,15 +13,16 @@
SECONDS_PER_HOUR = 60 * 60

AWS_REGION = os.environ["AWS_REGION"]
AWS_ACCESS_KEY = os.environ["AWS_ACCESS_KEY"]
AWS_SECRET_KEY = os.environ["AWS_SECRET_KEY"]

def from_env_or_default(variable_name, default_value):
if variable_name in os.environ:
return int(os.environ[variable_name])
return os.environ[variable_name]

return default_value

AWS_ACCESS_KEY = from_env_or_default("AWS_ACCESS_KEY", None)
AWS_SECRET_KEY = from_env_or_default("AWS_SECRET_KEY", None)

def is_near_month_end(now, forecast_length):
# Don't forecast unless there's sufficient time remaining in the month
last_day = calendar.monthrange(now.year, now.month)[1]
@@ -153,15 +154,15 @@ def send_email(from_address, env, region, forecast_length, lower, upper, mean, c

def main():
now = datetime.utcnow()
forecast_length = from_env_or_default("FORECAST_LENGTH", 7)
forecast_length = int(from_env_or_default("FORECAST_LENGTH", 7))

if now.day < forecast_length or is_near_month_end(now, forecast_length):
# Exit gracefully if it's near the start or end of the month
return

d = prepare_data(get_data(now))

use_grid = from_env_or_default("USE_GRID", 0)
use_grid = int(from_env_or_default("USE_GRID", 0))

if use_grid != 0:
pdq, seasonal_pdq = set_grid(qu=(0,use_grid))

0 comments on commit f0f27d7

Please sign in to comment.