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

Update as per peer review #8

Merged
merged 3 commits into from
Feb 8, 2024
Merged
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
34 changes: 22 additions & 12 deletions process.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@
" From FRED request's response, get the data as pandas DataFrame.\n",
" :return: pandas DataFrame with the values correctly parsed.\n",
" \"\"\"\n",
" url = BASE_URL + f'&api_key={api_key}&series_id={symbol}'\n",
" for retries in range(5):\n",
" try:\n",
" response = download_fred_symbol(symbol, api_key, session).json()\n",
Expand Down Expand Up @@ -684,22 +685,31 @@
"symbol_list = pd.DataFrame([i.split('|') for i in fred_time_series], columns=['Id', 'Name', 'Unit'])\n",
"session = requests.Session()\n",
"\n",
"for row in symbol_list.iterrows():\n",
" symbol = row[1].Id\n",
" name = row[1].Name\n",
"for retries in range(5):\n",
" try:\n",
" for row in symbol_list.iterrows():\n",
" symbol = row[1].Id\n",
" name = row[1].Name\n",
"\n",
" print(f'Downloading {name} ... ')\n",
" print(f'Downloading {name} ... ')\n",
"\n",
" df = get_dataframe_from_request(symbol, API_KEY, session)\n",
" \n",
" if df is None:\n",
" print(f'Download failed for {name} - observations were null')\n",
" continue\n",
" df = get_dataframe_from_request(symbol, API_KEY, session)\n",
" \n",
" if df is None:\n",
" print(f'Download failed for {name} - observations were null')\n",
" continue\n",
"\n",
" destination_file = destination_folder / f'{symbol.lower()}.csv'\n",
" df.to_csv(destination_file.resolve(), header=None, date_format='%Y%m%d')\n",
" destination_file = destination_folder / f'{symbol.lower()}.csv'\n",
" df.to_csv(destination_file.resolve(), header=None, date_format='%Y%m%d')\n",
"\n",
" sleep(1)"
" sleep(1)\n",
" break\n",
" except Exception as e:\n",
" if retries == 4:\n",
" raise Exception(f'Failed to download data')\n",
" \n",
" print(f'Failed to download data - retrying')\n",
" sleep(10)"
]
},
{
Expand Down
Loading