-
Notifications
You must be signed in to change notification settings - Fork 0
/
ical.py
executable file
·35 lines (32 loc) · 1.01 KB
/
ical.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
from flask import Blueprint
from flask import request
from flask import Response
import settings as s
ical = Blueprint("ical", __name__)
@ical.route("/e/<fn>.ics")
def try_ics(fn):
try:
return show_ics(fn)
except:
return False
def show_ics(fn):
with open(f"./data/{fn}", "r") as data:
data = data.read().splitlines()
with open("templates/ics.txt", "r") as temp:
temp = temp.read()
chars = {"<br>": "\\n", ",": "\,",
"<":"<", ">": ">",
"'":"'", """: "\"",
}
e = {"fn":fn, "iso":0, "title":0,
"host":0, "desc":0, "loc":0}
e["iso"] = f"{fn[:8]}T{fn[8:10]}0000Z"
e["title"] = data[0].replace(",", "\,")
e["host"] = data[1].split(">")[0].replace(",", "\,")
e["loc"] = data[2]
e["desc"] = data[3]
for c in chars:
if c in e["desc"]:
e["desc"] = e["desc"].replace(c, chars[c])
output = eval(f'f"""{temp}"""')
return Response(output, mimetype="text/calendar")