forked from NoLog.cz/trhlina-calendar
changes to json events from array
Adds support for webhook creation and init of events.json. I have no clue how i fixed it, or why does it work.
This commit is contained in:
parent
87e14c8d7b
commit
6427a50272
5 changed files with 20 additions and 23 deletions
|
@ -1,5 +1,4 @@
|
||||||
API-KEY=
|
API-KEY=
|
||||||
URL=
|
URL=
|
||||||
TIMEZONE=
|
TIMEZONE=
|
||||||
JSON-URL=
|
|
||||||
WEBHOOK-URL=
|
WEBHOOK-URL=
|
|
@ -72,15 +72,11 @@
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
hour12: false
|
hour12: false
|
||||||
},
|
},
|
||||||
events: [
|
failure: function() {
|
||||||
{% for event in events %}
|
alert('There was an error while fetching events from /events! ');
|
||||||
{
|
},
|
||||||
title: '{{ event.title }}',
|
events: '/events',
|
||||||
start: '{{ event.start }}',
|
|
||||||
end: '{{event.end}}'
|
|
||||||
},
|
|
||||||
{% endfor %}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
calendar.render();
|
calendar.render();
|
||||||
|
|
1
events.json
Normal file
1
events.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[{"title": "Closed", "start": "2024-02-25T09:00:00", "end": "2024-02-25T15:00:00"}, {"title": "Antigender - druh\u00e9 kolo", "start": "2024-03-05T18:00:00", "end": "2024-03-05T19:30:00"}, {"title": "Queer stitches nevim", "start": "2024-03-06T18:30:00", "end": "2024-03-06T20:00:00"}, {"title": "Queer stitches nevim", "start": "2024-03-20T19:30:00", "end": "2024-03-20T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-04-03T19:30:00", "end": "2024-04-03T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-04-17T19:30:00", "end": "2024-04-17T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-05-01T19:30:00", "end": "2024-05-01T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-05-15T19:30:00", "end": "2024-05-15T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-05-29T19:30:00", "end": "2024-05-29T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-06-12T19:30:00", "end": "2024-06-12T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-06-26T19:30:00", "end": "2024-06-26T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-07-10T19:30:00", "end": "2024-07-10T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-07-24T19:30:00", "end": "2024-07-24T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-08-07T19:30:00", "end": "2024-08-07T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-08-21T19:30:00", "end": "2024-08-21T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-09-04T19:30:00", "end": "2024-09-04T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-09-18T19:30:00", "end": "2024-09-18T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-10-02T19:30:00", "end": "2024-10-02T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-10-16T19:30:00", "end": "2024-10-16T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-10-30T19:30:00", "end": "2024-10-30T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-11-13T19:30:00", "end": "2024-11-13T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-11-27T19:30:00", "end": "2024-11-27T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-12-11T19:30:00", "end": "2024-12-11T21:00:00"}, {"title": "Queer stitches nevim", "start": "2024-12-25T19:30:00", "end": "2024-12-25T21:00:00"}, {"title": "Queer stitches nevim", "start": "2025-01-08T19:30:00", "end": "2025-01-08T21:00:00"}, {"title": "Queer stitches nevim", "start": "2025-01-22T19:30:00", "end": "2025-01-22T21:00:00"}, {"title": "Queer stitches nevim", "start": "2025-02-05T19:30:00", "end": "2025-02-05T21:00:00"}, {"title": "Queer stitches nevim", "start": "2025-02-19T19:30:00", "end": "2025-02-19T21:00:00"}, {"title": "Queer stitches nevim", "start": "2025-03-05T19:30:00", "end": "2025-03-05T21:00:00"}, {"title": "Prom\u00edt\u00e1n\u00ed T\u00e1bora solidarity", "start": "2024-03-22T18:00:00", "end": "2024-03-22T19:30:00"}]
|
10
get_json.py
10
get_json.py
|
@ -26,12 +26,13 @@ def offset_time(timestamp, offset):
|
||||||
return timestamp + timedelta(hours=offset)
|
return timestamp + timedelta(hours=offset)
|
||||||
|
|
||||||
|
|
||||||
def event_list_to_array(event_list):
|
def save_to_json(event_list):
|
||||||
event_array=[]
|
event_array=[]
|
||||||
for event in event_list:
|
for event in event_list:
|
||||||
event_array.append({"title":event[1], "start":event[0].strftime("%Y-%m-%dT%H:%M:%S"), "end":event[2].strftime("%Y-%m-%dT%H:%M:%S")})
|
event_array.append({"title":event[1], "start":event[0].strftime("%Y-%m-%dT%H:%M:%S"), "end":event[2].strftime("%Y-%m-%dT%H:%M:%S")})
|
||||||
return event_array
|
with open('events.json', 'w') as fp:
|
||||||
|
json.dump(event_array, fp)
|
||||||
|
|
||||||
|
|
||||||
def parse_time(timestring):
|
def parse_time(timestring):
|
||||||
if timestring!= None:
|
if timestring!= None:
|
||||||
|
@ -74,8 +75,7 @@ def create_event_list(json):
|
||||||
def main():
|
def main():
|
||||||
event_json = get_json(URL)
|
event_json = get_json(URL)
|
||||||
event_list = create_event_list(event_json)
|
event_list = create_event_list(event_json)
|
||||||
event_array = event_list_to_array(event_list)
|
save_to_json(event_list)
|
||||||
return event_array
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
17
main.py
17
main.py
|
@ -1,12 +1,11 @@
|
||||||
from flask import Flask, render_template, request
|
from flask import Flask, render_template, request
|
||||||
import get_json
|
import get_json
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
json_url = os.environ.get("JSON-URL")
|
|
||||||
webhook_update_url = os.environ.get("WEBHOOK-URL")
|
webhook_update_url = os.environ.get("WEBHOOK-URL")
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,13 +18,15 @@ def favicon():
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def home():
|
def home():
|
||||||
events = get_json.main()
|
#events = get_json.main()
|
||||||
return render_template('index.html', events=events)
|
#return render_template('index.html', events=events)
|
||||||
|
|
||||||
@app.route(json_url)
|
return render_template('index.html')
|
||||||
def summary():
|
|
||||||
x = "meme"
|
@app.route("/events")
|
||||||
return x
|
def server_json():
|
||||||
|
with open("events.json") as event_json:
|
||||||
|
return json.load(event_json)
|
||||||
|
|
||||||
@app.route(webhook_update_url, methods=['GET', 'POST'])
|
@app.route(webhook_update_url, methods=['GET', 'POST'])
|
||||||
def update():
|
def update():
|
||||||
|
|
Loading…
Reference in a new issue