-<table width=99%% cellspacing=10 border=0>
- <tr>"""
- % text_location
- )
- count = parsed_json["cnt"]
-
- ts = {}
- highs = {}
- lows = {}
- wind = {}
- conditions = {}
- rain = {}
- snow = {}
- for x in range(0, count):
- data = parsed_json["list"][x]
- dt = data["dt_txt"] # 2019-10-07 18:00:00
- date = dt.split(" ")[0]
- time = dt.split(" ")[1]
- wind[date] = []
- conditions[date] = []
- highs[date] = -99999
- lows[date] = +99999
- rain[date] = []
- snow[date] = []
- ts[date] = 0
-
- for x in range(0, count):
- data = parsed_json["list"][x]
- dt = data["dt_txt"] # 2019-10-07 18:00:00
- date = dt.split(" ")[0]
- time = dt.split(" ")[1]
- _ = data["dt"]
- if _ > ts[date]:
- ts[date] = _
- temp = data["main"]["temp"]
- if highs[date] < temp:
- highs[date] = temp
- if temp < lows[date]:
- lows[date] = temp
- wind[date].append(data["wind"]["speed"])
- conditions[date].append(data["weather"][0]["main"])
- 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}}
-
- # Next 5 half-days
- # for x in xrange(0, 5):
- # fcast = parsed_json['forecast']['txt_forecast']['forecastday'][x]
- # text = fcast['fcttext']
- # text = re.subn(r' ([0-9]+)F', r' \1°F', text)[0]
- # f.write('<td style="vertical-align:top;font-size:75%%"><P STYLE="padding:8px;">%s</P></td>' % text)
- # f.write('</tr></table>')
- # f.close()
- # return True
-
- # f.write("<table border=0 cellspacing=10>\n")
- days_seen = {}
- for date in sorted(highs.keys()):
- today = datetime.fromtimestamp(ts[date])
- formatted_date = today.strftime("%a %e %b")
- if formatted_date in days_seen:
- continue
- days_seen[formatted_date] = True
- num_days = len(list(days_seen.keys()))
-
- days_seen = {}
- for date in sorted(highs.keys()):
- precip = 0.0
- for _ in rain[date]:
- precip += _
- for _ in snow[date]:
- precip += _
-
- today = datetime.fromtimestamp(ts[date])
- formatted_date = today.strftime("%a %e %b")
- if formatted_date in days_seen:
- continue
- days_seen[formatted_date] = True
- f.write('<td width=%d%% style="vertical-align:top;">\n' % (100 / num_days))
- f.write("<table border=0>\n")
-
- # Date
- f.write(
- " <tr><td colspan=3 height=50><b><center><font size=6>"
- + formatted_date
- + "</font></center></b></td></tr>\n"
- )
-
- # Icon
- f.write(
- ' <tr><td colspan=3 height=100><center><img src="/icons/weather/%s" height=125></center></td></tr>\n'
- % self.pick_icon(conditions[date], rain[date], snow[date])
- )
-
- # Low temp
- color = "#000099"
- if lows[date] <= 32.5:
- color = "#009999"
- f.write(
- ' <tr><td width=33%% align=left><font color="%s"><b>%d°F </b></font></td>\n'
- % (color, int(lows[date]))
- )
-
- # Total precip
- precip *= 0.0393701
- if precip > 0.025:
+""")
+ count = parsed_json["cnt"]
+
+ ts = {}
+ highs = {}
+ lows = {}
+ wind: Dict[str, List[float]] = {}
+ conditions: Dict[str, List[str]] = {}
+ rain: Dict[str, List[float]] = {}
+ snow: Dict[str, List[float]] = {}
+ precip: Dict[str, List[float]] = {}
+
+ 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(' ')
+ wind[date] = []
+ conditions[date] = []
+ highs[date] = None
+ lows[date] = None
+ rain[date] = []
+ snow[date] = []
+ precip[date] = []
+ ts[date] = 0
+
+ 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 _ > ts[date]:
+ ts[date] = _
+ temp = data["main"]["temp"]
+ if highs[date] is None or highs[date] < temp:
+ highs[date] = temp
+ if lows[date] is None or temp < lows[date]:
+ lows[date] = temp
+ wind[date].append(data["wind"]["speed"])
+ conditions[date].append(data["weather"][0]["main"])
+ 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}%'
+
+ precip[date] = []
+ aggregate_precip = 0.0
+ for r, s in zip(rain[date], snow[date]):
+ aggregate = r + s
+ aggregate_precip += aggregate
+ precip[date].append(aggregate)
+ 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)