Commit bc602022 authored by STEINMETZ THOMAS's avatar STEINMETZ THOMAS
Browse files

Merge branch 'feature/prevision-weather' into 'develop'

Feature/prevision weather

See merge request !5
parents 4e42e078 cfaa7925
......@@ -15,20 +15,59 @@ Options:
--version Show version.
"""
import json
from docopt import docopt
import requests
def city(arguments):
if arguments['<city_name>'] and arguments['--raw']:
r = requests.get('https://richie.u-strasbg.fr/~virgile/sf4/public/index.php/weather/city/'+arguments['<city_name>'],
headers={"apiKey":"PommeTacosDockerBatiment"})
print(r.content)
def city_raw(city_name):
"""Function city_raw
Args:
city_name (string): city's name
Returns:
string: response
"""
response = requests.get('https://richie.u-strasbg.fr/~virgile/sf4/public/ \
index.php/weather/city/'+city_name,
headers={"apiKey":"PommeTacosDockerBatiment"}
)
return response.text
def city(args):
"""Function city
Args:
args (array): arguments in command line
Returns:
string|None: response city
"""
if args['<city_name>'] and args['--raw']:
return city_raw(args['<city_name>'])
return None
def forecast(args):
"""function forecast
Args:
args (array): arguments in command line
"""
if args['<city_name>']:
data_city = city_raw(args['<city_name>'])
city_id = json.loads(data_city)['id']
response = requests.get('https://richie.u-strasbg.fr/~virgile/sf4/\
public/index.php/weather/forecast/'+str(city_id),
headers={"apiKey":"PommeTacosDockerBatiment"})
print(response.text)
if __name__ == '__main__':
arguments = docopt(__doc__, version='0.1')
if arguments['city']:
city(arguments);
print(city(arguments))
elif arguments['forecast']:
forecast(arguments)
else:
print(arguments)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment