This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
webapp.py
61 lines (48 loc) · 1.67 KB
/
webapp.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
import traceback
import json
import sys
import os
import base64
from datetime import datetime, timedelta
from icalendar import Calendar, Event
from notion.client import NotionClient
from notion_ics import get_ical
from flask import Flask, request, make_response
with open('settings.json') as f:
settings = json.load(f)
token = settings['token']
client = NotionClient(settings['token'], monitor=False)
with open('create_url.html') as f:
index = f.read()
app = Flask(__name__)
@app.route('/')
def create_url():
return index
@app.route('/ics')
def make_ics():
try:
try:
calendar_url = base64.b64decode(request.args['url']).decode()
title_format = base64.b64decode(request.args['format']).decode()
except Exception as e:
raise Exception('Something went wrong with the given parameters') from e
cal = get_ical(client, calendar_url, title_format)
text = cal.to_ical()
except Exception as e:
traceback.print_exc()
# put it in calendar
cal = Calendar()
cal.add("summary", "Imported from Notion, via notion-export-ics, but failed.")
cal.add('version', '2.0')
for i in range(7):
event = Event()
event.add('dtstart', datetime.now().date() + timedelta(days=i))
event.add('summary', repr(e))
cal.add_component(event)
text = cal.to_ical()
res = make_response(text)
res.headers.set('Content-Disposition', 'attachment;filename=calendar.ics')
res.headers.set('Content-Type', 'text/calendar;charset=utf-8')
return res
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)