Minimalistic Python script to prompt a shell user for cities and print weather stats for them.
- Sign up for an OpenWeather account
- Confirm your email address
- Go to API keys and copy the default key (or create a custom one)
-
Clone this repository
git clone {paste-url} -
Add your API key as an environment variable
export OPENWEATHER_API_KEY={YOUR API KEY} -
Install dependencies
poetry install
- Run the script
poetry run python turfcoach/weather.py --city "San Francisco" --city Berlin --city Dublin --city Lima
-
Minimal filestructure: One could argue to extract the code in
weather.pyinto all kinds of files. With the scope as it is, I believe the simplicity of one file outweighs the benefits of a more nuanced file structure. -
Poetry: I went for Poetry over
pyenv,venv,virtualwrapper, etc simply because I hadn't tried it yet and was curious. -
Async: For a larger project of this kind I would strongly consider async or some coroutine library, not only to parallelize fetch requests for muliple cities. As it is, this seemed the simplest way to the target.
-
Env variables: Usually I'd put sensitive data into an
.envfile (and exclude that from VCS) or use the secret management of the cloud provider. -
Other bells and whistles: I considered adding custom exceptions, tests, a license,
.gitignore, and a proper frontend but, again, decided for the MVP version.
clickfor a minimal command-line interfacerequestsfor convenient API calls (instead ofurllib.request)plotextfor printing a histogram to the command line
While a large-scale application might benefit from pandas, I deliberately went for dictionaries for the sake of simplicity.