Format a notification.
This commit is contained in:
@@ -6,6 +6,7 @@ recommend that Dennis buys witbier.
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import textwrap
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
@@ -31,6 +32,28 @@ def get_maxima(weather):
|
|||||||
return days
|
return days
|
||||||
|
|
||||||
|
|
||||||
|
def notify(best_day, best_temp):
|
||||||
|
best_day = best_day.strftime('%d/%m')
|
||||||
|
|
||||||
|
message = f'''\
|
||||||
|
Lief DB,
|
||||||
|
|
||||||
|
De komende dagen wordt het wederom prachtig weer. Zo wordt het
|
||||||
|
op {best_day} maar liefst {best_temp} °C!
|
||||||
|
|
||||||
|
Met zulke mooie berichten kan het niet anders dan dat er
|
||||||
|
binnenkort witbier verkocht wordt. Toch? Ik kijk er in ieder
|
||||||
|
geval naar uit.
|
||||||
|
|
||||||
|
Knuffels,
|
||||||
|
|
||||||
|
Witbierbot.
|
||||||
|
'''
|
||||||
|
|
||||||
|
message = textwrap.dedent(message)
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
@@ -38,7 +61,10 @@ def main():
|
|||||||
else:
|
else:
|
||||||
weather = load_weather()
|
weather = load_weather()
|
||||||
|
|
||||||
print(get_maxima(weather))
|
maxima = get_maxima(weather)
|
||||||
|
best, temp = max(maxima.items(), key=lambda x: x[1])
|
||||||
|
if temp > 10:
|
||||||
|
notify(best, temp)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user