Created
October 26, 2020 02:19
-
-
Save yaojenkuo/71d41595b6847dc6b7b95927acac20c4 to your computer and use it in GitHub Desktop.
A try-except demo in class on 2020-10-26.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import datetime as dt | |
today = dt.date.today() | |
day_delta = dt.timedelta(1) | |
while True: | |
try: | |
today_str = today.strftime('%m-%d-%Y') | |
print("嘗試載入 {} 的資料...".format(today_str)) | |
csv_url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/{}.csv'.format(today_str) | |
daily_report = pd.read_csv(csv_url) | |
print("Congrats! 成功載入了 {} 的資料!".format(today_str)) | |
break | |
except: | |
print("Sorry, {} 的資料還找不到 QQ".format(today_str)) | |
today -= day_delta #today = today - day_delta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment