Closed jdebacker closed 2 months ago
To be resolved:
get_fert
or get_mort
) and supply their token to the API? Current changes are to just ask for it when one pings get_pop_obj
and that call requires fetching data from the UN.One idea is to include:
global UN_TOKEN
# Check for a file named "un_api_token.txt" in the current directory
if os.path.exists(os.path.join("un_api_token.txt")):
with open(os.path.join("un_api_token.txt"), "r") as file:
UN_TOKEN = file.read().strip()
else: # if file not exist, prompt user for token
UN_TOKEN = input("Please enter your UN API token: ")
in get_un_data
, but have a command following the user input prompt to save the token to a file named un_api_token.txt
. This way, on subsequent calls to the API, the token is just read from a file.
Would there be any security concerns with this? e.g., a user's token saved on a device that isn't theirs?
To solve that, we can have a separate prompt, for "save token to disk" and only write to disk if yes...
For the ability to use cached files and change the start/end year, we need to save the year as a variables to the output files (fert_rates.csv
, etc.)
Attention: Patch coverage is 31.11111%
with 31 lines
in your changes missing coverage. Please review.
Project coverage is 71.92%. Comparing base (
e762b06
) to head (138a981
).
This PR now handles UN data access in the following way:
un_api_token.txt
for future use.@rickecon @SeaCelo, let me know if the changes in demographics.py
look good to you.
@jdebacker This is a sensible approach. I'll test it and see if there are any issues
@jdebacker. This looks great. Merging as soon as tests pass. I just committed one extra change at the end of CHANGELOG.md
that adds the hyperlink.
This PR updates the
demographics.py
module for updates in the UN WPP data portal API, which now requires users to authenticate with an API token.The PR: 1) Changes the calls to the API to download multiple years at a time, which significantly reduces the number of API calls (Issue #935) 2) Has
demographics.py
look for a file namedun_api_token.txt
in the current directory, and if not there, prompts the user to enter their API token in the command line (Issue #931). 3) Add functionality to read in cached files, pulling the years of data one wants from them. [NOT YET STARTED]