1
0

Initial work on loading data from the API.

This commit is contained in:
2019-02-25 15:43:55 +01:00
commit 3855cc2889
2 changed files with 40 additions and 0 deletions

33
witbierbot.py Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env python3
"""
Read weather predictions for the next days, and if it's high enough,
recommend that Dennis buys witbier.
"""
import datetime
import json
import os
import sys
from urllib.request import urlopen
def load_weather():
url = 'https://api.openweathermap.org/data/2.5/forecast?q=Leiden' \
+ '&units=metric' \
+ '&appid=' + os.environ['API_KEY']
result = urlopen(url)
return json.load(result)
def main():
if len(sys.argv) > 1:
with open(sys.argv[1]) as f:
weather = json.load(f)
else:
weather = load_weather()
print(weather)
if __name__ == '__main__':
main()