Skip to content

Commit

Permalink
fix working with text caching
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor-phil committed Nov 5, 2024
1 parent 3e0de6d commit 31ccb5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Binary file modified lectures/_data/avalanche_forecasts.zip
Binary file not shown.
14 changes: 8 additions & 6 deletions lectures/applications/working_with_text.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def get_forecasts(start, end, region):
#print("working on {}, {}".format(region,day))
forecasts = forecasts + [get_forecast(day, region)]
#print("sleeping")
time.sleep(0.05) # to avoid too much load on Avalanche Canada servers
time.sleep(0.01) # to avoid too much load on Avalanche Canada servers
day = day + pd.Timedelta(1,"D")
return(forecasts)
Expand All @@ -458,11 +458,13 @@ def get_season(year, region):
os.mkdir("avalanche_forecasts")
seasonfile = "avalanche_forecasts/{}_{}-{}.json".format(region, year, year+1)
if (not os.path.isfile(seasonfile)):
startdate = pd.to_datetime("{}-{}-{} 12:00".format(year, start_month, start_day))
lastdate = pd.to_datetime("{}-{}-{} 12:00".format(year+1, last_month, last_day))
season = get_forecasts(startdate,lastdate,region)
with open(seasonfile, 'w') as outfile:
json.dump(season, outfile, ensure_ascii=False)
print(f"Season file {seasonfile} not found. Uncomment code here to update cached data")
season = []
#startdate = pd.to_datetime("{}-{}-{} 12:00".format(year, start_month, start_day))
#lastdate = pd.to_datetime("{}-{}-{} 12:00".format(year+1, last_month, last_day))
#season = get_forecasts(startdate,lastdate,region)
#with open(seasonfile, 'w') as outfile:
# json.dump(season, outfile, ensure_ascii=False)
else:
with open(seasonfile, "rb") as json_data:
season = json.load(json_data)
Expand Down

2 comments on commit 31ccb5c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.