Skip to content

Conversation

@Turreted
Copy link
Contributor

@Turreted Turreted commented Mar 25, 2020

Note that this only works for countries, and will return None is a province is specified. Also note that this does not add anything to that API, It simply extends the location object.
All data is pulled from the World Bank, and can be found Here

@Turreted Turreted mentioned this pull request Mar 25, 2020
@ExpDev07
Copy link
Owner

ExpDev07 commented Mar 25, 2020

Nice work. Just throwing this out there: would it perhaps be better to name the property country_population, meaning people can access it in every location, but it's explicitly marked that it belongs to the country?

Also, I think you should move the countrypopulation method over to /utils, perhaps under /utils/population? Still keep the caching mechanism though.

@ExpDev07 ExpDev07 linked an issue Mar 25, 2020 that may be closed by this pull request
@Turreted
Copy link
Contributor Author

Should be good to go!

I can't test everything locally (pipenv's being annoying), so if you might want to verify that everything works as intended before merging

@ExpDev07
Copy link
Owner

Thanks for this! I'll look over it and merge.

@Turreted
Copy link
Contributor Author

Is this ready to merge or are there more changes that I should make?

@ExpDev07
Copy link
Owner

@Turreted hey, while testing, your initial data-source was missing populations for a bunch of countries, so I decided to look for another one. I opted with https://www.geonames.org/ and they seem to provide relatively updated populations as well as for every country we currently have.

The populations are now also fetched when starting the app. There's no point of having a refresh cache mechanism on it as it probably doesn't update very often so, so it's fine to just retrieve the data on startup instead.

Looks good to go now.

return mappings

# Mapping of alpha-2 codes country codes to population.
populations = fetch_populations()
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could make this a "start_up event"
https://fastapi.tiangolo.com/advanced/events/

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, it seems to work on startup now though? @Kilo59

Copy link
Collaborator

@Kilo59 Kilo59 Mar 26, 2020

Choose a reason for hiding this comment

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

Absolutely, what you have here looks like it would work fine. Just pointing out a feature of FastAPI.

Copy link
Owner

Choose a reason for hiding this comment

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

@Kilo59 alright :) We can look at it later. Now populations should work all perfectly. That's a nice feature.

@ExpDev07 ExpDev07 merged commit 1be9af5 into ExpDev07:master Mar 26, 2020
@ExpDev07
Copy link
Owner

@all-contributors please add @Turreted for code.

@allcontributors
Copy link
Contributor

@ExpDev07

I've put up a pull request to add @Turreted! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add population data

3 participants