+ count = parsed_json["cnt"]
+
+ ts = {}
+ highs = {}
+ lows = {}
+ wind: Dict[str, List[float]] = defaultdict(list)
+ conditions: Dict[str, List[str]] = defaultdict(list)
+ rain: Dict[str, List[float]] = defaultdict(list)
+ snow: Dict[str, List[float]] = defaultdict(list)
+ precip: Dict[str, List[float]] = defaultdict(list)
+
+ for x in range(0, count):
+ data = parsed_json["list"][x]
+ dt = data["dt_txt"] # 2019-10-07 18:00:00
+ (date, time) = dt.split(" ")
+ _ = data["dt"]
+ if _ not in ts or _ > ts[date]:
+ ts[date] = _
+ temp = data["main"]["temp"]
+
+ # High and low temp
+ if date not in highs or highs[date] < temp:
+ highs[date] = temp
+ if date not in lows or lows[date] > temp:
+ lows[date] = temp
+
+ # Windspeed and conditions
+ wind[date].append(data["wind"]["speed"])
+ conditions[date].append(data["weather"][0]["main"])
+
+ # 3h precipitation (rain / snow)
+ if "rain" in data and "3h" in data["rain"]:
+ rain[date].append(data["rain"]["3h"])
+ else:
+ rain[date].append(0)
+ if "snow" in data and "3h" in data["snow"]:
+ snow[date].append(data["snow"]["3h"])
+ else:
+ snow[date].append(0)
+
+ # {u'clouds': {u'all': 0},
+ # u'sys': {u'pod': u'd'},
+ # u'dt_txt': u'2019-10-09 21:00:00',
+ # u'weather': [
+ # {u'main': u'Clear',
+ # u'id': 800,
+ # u'icon': u'01d',
+ # u'description': u'clear sky'}
+ # ],
+ # u'dt': 1570654800,
+ # u'main': {
+ # u'temp_kf': 0,
+ # u'temp': 54.74,
+ # u'grnd_level': 1018.95,
+ # u'temp_max': 54.74,
+ # u'sea_level': 1026.46,
+ # u'humidity': 37,
+ # u'pressure': 1026.46,
+ # u'temp_min': 54.74
+ # },
+ # u'wind': {u'speed': 6.31, u'deg': 10.09}}
+
+ days_seen = set()
+ for date in sorted(highs.keys()):
+ day = datetime.fromtimestamp(ts[date])
+ formatted_date = day.strftime("%a %e %b")
+ if formatted_date in days_seen:
+ continue
+ days_seen.add(formatted_date)
+ total = len(days_seen)
+
+ first_day = True
+ days_seen = set()
+ for n, date in enumerate(sorted(highs.keys())):
+ if n % 3 == 0:
+ if n > 0:
+ f.write("</div>")
+ f.write('<div STYLE="overflow:hidden; width:100%; height:500px">')
+ remaining = total - n
+ if remaining >= 3:
+ width = "33%"
+ else:
+ width = f"{100/remaining}%"
+
+ aggregate_daily_precip = 0.0
+ for r, s in zip(rain[date], snow[date]):
+ hourly_aggregate = r + s
+ aggregate_daily_precip += hourly_aggregate
+ precip[date].append(hourly_aggregate)
+ logger.debug(
+ f"Aggregate precip on {date} was {aggregate_daily_precip} cm"
+ )
+ if first_day:
+ while len(precip[date]) < 8:
+ precip[date].insert(0, 0)
+ first_day = False
+
+ day = datetime.fromtimestamp(ts[date])
+ formatted_date = day.strftime("%a %e %b")
+ if formatted_date in days_seen:
+ continue
+ days_seen.add(formatted_date)
+ f.write(
+ f'<div style="width:{width}; height:500px; float:left"><table>\n'
+ )