-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (28 loc) · 877 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
import json
import os
from datetime import datetime
import urllib3
from converter import convert, createDatabaseDir
dataFolder = os.path.abspath('') + "data/"
def fetch():
apiURL = "https://www.tagesschau.de/api2/"
dateTimeObj = datetime.now()
timestamp = dateTimeObj.strftime("%d-%m-%Y--%H-%M-%S")
http = urllib3.PoolManager()
request = http.request('GET', apiURL)
if (request.status != 200):
return
jsonData = json.loads(request.data.decode('utf-8'))
convert(jsonData=jsonData, timestamp=timestamp)
"""
filename = timestamp + ".json"
if not os.path.isfile(dataFolder + filename):
open(dataFolder + filename, "x")
file = open(dataFolder + filename, "w")
file.write(json.dumps(jsonData))
file.close()
"""
if __name__ == "__main__":
createDatabaseDir()
fetch()