Commit 6a590a2d authored by GAYDAMAKHA MIKHAIL's avatar GAYDAMAKHA MIKHAIL
Browse files

Merge branch 'feature/manage_slots_number' into 'develop'

 manage number of slots #6

See merge request !10
parents 132ab6db d990ba69
......@@ -6,11 +6,11 @@ Usage: -h | --help | --version
--tc Temperature celsius.
--tf Temperature fahrenheit.
--tk Temperature Kelvin.
--raw Brut data.
-n number days.
--tc Temperature in Celsius.
--tf Temperature in Fahrenheit.
--tk Temperature in Kelvin.
--raw Raw data.
-n Number of slots.
-h --help Show this screen.
--version Show version.
......@@ -101,7 +101,13 @@ def forecast(args):
city_id = json.loads(data_city)['id']
response = requests.get('' +
'weather/forecast/'+str(city_id), headers={"apiKey": API_KEY})
json_response = json.loads(response.text)
previsions = json.loads(response.text)['list']
if args['<slots>'] is not None:
slots_number = int(args['<slots>'])
if slots_number is not None and slots_number <= 0:
return 'Slots number must be a positive integer'
if slots_number is not None:
del previsions[slots_number:]
if args['--tc']:
temp_unit = TempUnit.CELSIUS
elif args['--tf']:
......@@ -109,7 +115,7 @@ def forecast(args):
temp_unit = TempUnit.KELVIN
formatted = []
for prevision in json_response['list']:
for prevision in previsions:
date_time = datetime.fromtimestamp(prevision['dt']).isoformat()
weather_description = prevision['weather'][0]['description']
temperature = temp_convert(
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