-
Notifications
You must be signed in to change notification settings - Fork 0
/
service
executable file
·67 lines (57 loc) · 1.64 KB
/
service
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
from time import sleep, time
from datetime import date
from requests import Session
import json
import shutil
import os
URL = "https://www.chaosdorf.de/~ytvwld/freitagsfoo.json"
LOADING_DATA = {
"hosts": ["..."],
"date": str(date.today()),
"talks": [{
"title": "...",
"description": "...",
"persons": [],
}]
}
FILENAME = "freitagsfoo.json"
FOLDERS_TO_WRITE = (".", "talks_screen", "title_screen", "next_screen")
def save_bytes(content):
curr_time = time()
filename = "freitagsfoo-%s.json" % str(curr_time)
f = open(filename, "wb")
f.write(content)
f.close()
for folder in FOLDERS_TO_WRITE:
shutil.copy(filename, "{}/{}".format(folder, FILENAME))
os.remove(filename)
def break_up_text(text: str) -> str:
lines = []
for line in text.splitlines():
lines += break_up_line(line)
return "\n".join(lines)
def break_up_line(line: str) -> list:
lines = []
curr_line = ""
words = line.split(" ")
while words:
for word in words[:]:
speculative_line = curr_line + " " + word
if len(speculative_line) >= 50:
lines.append(curr_line)
curr_line = ""
break
words.pop(0)
curr_line = speculative_line
else:
lines.append(curr_line)
return lines
save_bytes(json.dumps(LOADING_DATA).encode())
session = Session()
while True:
data = session.get(URL).json()
for talk in data["talks"]:
talk["description"] = break_up_text(talk["description"])
save_bytes(json.dumps(data, ensure_ascii=False).encode())
sleep(60)