Skip to content

Commit

Permalink
[WDI Indicator Download] Provide a default filename for WDI download (d…
Browse files Browse the repository at this point in the history
…atacommonsorg#982)

* Provide a default filename for WDI download

* Adding a helpful print statement
  • Loading branch information
jehangiramjad authored Feb 12, 2024
1 parent 55694a8 commit 0f5ee41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions scripts/world_bank/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
preprocessed_source_csv
download_indicators/*.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import numpy as np
import pandas as pd

_OUT_PATH = flags.DEFINE_string('out_path', None, 'CNS path to write output.')
# The output path should have a default filename.
_OUT_DEFAULT_NAME = 'cleaned_wdi.csv'
_OUT_PATH = flags.DEFINE_string('out_path', _OUT_DEFAULT_NAME,
'CNS path to write output.')

indicators = [
'SP.POP.TOTL',
Expand Down Expand Up @@ -72,6 +75,7 @@ def DownloadAndParseCsvs() -> None:
"""
dat = []
for indicator in indicators:
print(f'DOWNLOADING: {indicator}....')
resp = urllib.request.urlopen(
f'http://api.worldbank.org/v2/country/all/indicator/{indicator}?source=2&downloadformat=csv'
)
Expand Down Expand Up @@ -121,6 +125,8 @@ def DownloadAndParseCsvs() -> None:
'unit',
],
)
# Write to the _OUT_PATH which defaults to the output filename
# if no path is provided.
with open(_OUT_PATH.value, 'w+') as f_out:
out_df.to_csv(f_out, index=False)

Expand Down

0 comments on commit 0f5ee41

Please sign in to comment.