updating latest from mac
This commit is contained in:
13
weather-cli/src/weather_cli/__init__.py
Normal file
13
weather-cli/src/weather_cli/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from .__version__ import __version__ # noqa
|
||||
import requests
|
||||
|
||||
|
||||
def current_weather(location, api_key):
|
||||
url = 'https://api.openweathermap.org/data/2.5/weather'
|
||||
|
||||
query_params = {
|
||||
'q': location,
|
||||
'appid': api_key,
|
||||
}
|
||||
response = requests.get(url, params=query_params)
|
||||
return response.json()['weather'][0]['description']
|
||||
1
weather-cli/src/weather_cli/__version__.py
Normal file
1
weather-cli/src/weather_cli/__version__.py
Normal file
@@ -0,0 +1 @@
|
||||
__version__ = '0.1.0'
|
||||
0
weather-cli/src/weather_cli/console/__init__.py
Normal file
0
weather-cli/src/weather_cli/console/__init__.py
Normal file
27
weather-cli/src/weather_cli/console/console.py
Normal file
27
weather-cli/src/weather_cli/console/console.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import weather_cli
|
||||
import click
|
||||
|
||||
|
||||
@click.group()
|
||||
@click.version_option(version=weather_cli.__version__)
|
||||
def main(version):
|
||||
pass
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.argument('location')
|
||||
@click.option(
|
||||
'--api-key', '-a', help='your API key for the OpenWeatherMap API'
|
||||
)
|
||||
def current(location: str, api_key: str):
|
||||
"""Query the openWeather API for the current weather conditions
|
||||
"""
|
||||
# import pudb; pudb.set_trace()
|
||||
if api_key is None:
|
||||
api_key = weather_cli.SAMPLE_API_KEY
|
||||
weather = weather_cli.current_weather(location=location, api_key=api_key)
|
||||
print(f'The weather in {location} is {weather}')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user