-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt-demystyfy.py
68 lines (61 loc) · 2.07 KB
/
decrypt-demystyfy.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
#
# Provides the TLS-encrypted, JSONified data of chaosdorf.de/~ytvwld/freitagsfoo.json in a simple, readable format.
#
from http.server import BaseHTTPRequestHandler, HTTPServer
import requests
import logging
import json
freitagsfooURL = "https://chaosdorf.de/~ytvwld/freitagsfoo.json"
def getTalks():
r = requests.get(freitagsfooURL)
if r.status_code != 200:
logging.error(f"Failed to get talks: code {r.status_code} received\n")
return
data = json.loads(r.text)
if "talks" not in data:
logging.error("Failed to read talks: no talks found\n")
return
out = ""
for t in data["talks"]:
speaker = ", ".join(t["persons"])
out += speaker + ";;;" + t['title'] + "\n"
return out
def getInfo():
r = requests.get(freitagsfooURL)
if r.status_code != 200:
logging.error(f"Failed to get info: code {r.status_code} received\n")
return
data = json.loads(r.text)
if "hosts" not in data or "date" not in data:
logging.error("Failed to read info: no info found\n")
return
hosts = ", ".join(data["hosts"])
return f"{hosts};;;{data['date']}"
class TheHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/talks":
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(getTalks().encode("utf-8"))
elif self.path == "/info":
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(getInfo().encode("utf-8"))
else:
self.send_response(404)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b"404 - not found")
def runServer():
server_address = ('', 8080)
httpd = HTTPServer(server_address, TheHandler)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
if __name__ == '__main__':
runServer()