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

Add an environment variable to prevent updating #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
48 changes: 25 additions & 23 deletions nflgame/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import json
import os.path
from os import environ

__pdoc__ = {}

Expand Down Expand Up @@ -69,29 +70,30 @@ def _create_schedule(jsonf=None):
sched[gsis_id] = info
last_updated = datetime.datetime.utcfromtimestamp(data.get('time', 0))

if (datetime.datetime.utcnow() - last_updated).total_seconds() >= day:
# Only try to update if we can write to the schedule file.
if os.access(jsonf, os.W_OK):
import nflgame.live
import nflgame.update_sched
year, week = nflgame.live.current_year_and_week()
phase = nflgame.live._cur_season_phase
current_week = (year, phase, week)

missing_weeks = check_missing_weeks(sched, year, phase)
weeks_to_update = order_weeks_to_update(missing_weeks, current_week)

for week_to_update in weeks_to_update:
print(('Updating {}').format(week_to_update))
year, phase, week = week_to_update
week_was_updated = nflgame.update_sched.update_week(sched, year, phase, week)
if not week_was_updated:
print(("Week {}{} of {} was either empty, or it couldn't be fetched from NFL.com. Aborting.")\
.format(phase , week, year))
break

nflgame.update_sched.write_schedule(jsonf, sched)
last_updated = datetime.datetime.utcnow()
if not environ.get('NFLGAME_SKIP_UPDATE', '').lower() == 'true':
if (datetime.datetime.utcnow() - last_updated).total_seconds() >= day:
# Only try to update if we can write to the schedule file.
if os.access(jsonf, os.W_OK):
import nflgame.live
import nflgame.update_sched
year, week = nflgame.live.current_year_and_week()
phase = nflgame.live._cur_season_phase
current_week = (year, phase, week)

missing_weeks = check_missing_weeks(sched, year, phase)
weeks_to_update = order_weeks_to_update(missing_weeks, current_week)

for week_to_update in weeks_to_update:
print(('Updating {}').format(week_to_update))
year, phase, week = week_to_update
week_was_updated = nflgame.update_sched.update_week(sched, year, phase, week)
if not week_was_updated:
print(("Week {}{} of {} was either empty, or it couldn't be fetched from NFL.com. Aborting.")\
.format(phase , week, year))
break

nflgame.update_sched.write_schedule(jsonf, sched)
last_updated = datetime.datetime.utcnow()

return sched, last_updated

Expand Down