Compute maxima by day.
This commit is contained in:
@@ -7,6 +7,7 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from collections import defaultdict
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
@@ -20,13 +21,24 @@ def load_weather():
|
|||||||
return json.load(result)
|
return json.load(result)
|
||||||
|
|
||||||
|
|
||||||
|
def get_maxima(weather):
|
||||||
|
days = defaultdict(float)
|
||||||
|
for day in weather['list']:
|
||||||
|
instant = datetime.datetime.fromtimestamp(day['dt'])
|
||||||
|
date = instant.date()
|
||||||
|
days[date] = max(days[date], day['main']['temp_max'])
|
||||||
|
|
||||||
|
return days
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
with open(sys.argv[1]) as f:
|
with open(sys.argv[1]) as f:
|
||||||
weather = json.load(f)
|
weather = json.load(f)
|
||||||
else:
|
else:
|
||||||
weather = load_weather()
|
weather = load_weather()
|
||||||
print(weather)
|
|
||||||
|
print(get_maxima(weather))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user