From 6427a502721d920115f06b697a998521736b7126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pta=CC=81k?= Date: Sun, 25 Feb 2024 10:09:00 +0100 Subject: [PATCH] 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. --- .env-example | 1 - conf/templates/index.html | 14 +++++--------- events.json | 1 + get_json.py | 10 +++++----- main.py | 17 +++++++++-------- 5 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 events.json diff --git a/.env-example b/.env-example index 511ef86..70c6538 100644 --- a/.env-example +++ b/.env-example @@ -1,5 +1,4 @@ API-KEY= URL= TIMEZONE= -JSON-URL= WEBHOOK-URL= \ No newline at end of file diff --git a/conf/templates/index.html b/conf/templates/index.html index 081c16e..0205aef 100644 --- a/conf/templates/index.html +++ b/conf/templates/index.html @@ -72,15 +72,11 @@ minute: '2-digit', hour12: false }, - events: [ - {% for event in events %} - { - title: '{{ event.title }}', - start: '{{ event.start }}', - end: '{{event.end}}' - }, - {% endfor %} - ] + failure: function() { + alert('There was an error while fetching events from /events! '); + }, + events: '/events', + }); calendar.render(); diff --git a/events.json b/events.json new file mode 100644 index 0000000..8b05f7b --- /dev/null +++ b/events.json @@ -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"}] \ No newline at end of file diff --git a/get_json.py b/get_json.py index 872fb7a..2ad54ec 100644 --- a/get_json.py +++ b/get_json.py @@ -26,12 +26,13 @@ def offset_time(timestamp, offset): return timestamp + timedelta(hours=offset) -def event_list_to_array(event_list): +def save_to_json(event_list): event_array=[] 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")}) - return event_array - + with open('events.json', 'w') as fp: + json.dump(event_array, fp) + def parse_time(timestring): if timestring!= None: @@ -74,8 +75,7 @@ def create_event_list(json): def main(): event_json = get_json(URL) event_list = create_event_list(event_json) - event_array = event_list_to_array(event_list) - return event_array + save_to_json(event_list) if __name__ == "__main__": main() diff --git a/main.py b/main.py index 36c0103..0fdbfc6 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,11 @@ from flask import Flask, render_template, request import get_json - from dotenv import load_dotenv import os +import json load_dotenv() -json_url = os.environ.get("JSON-URL") webhook_update_url = os.environ.get("WEBHOOK-URL") @@ -19,13 +18,15 @@ def favicon(): @app.route('/') def home(): - events = get_json.main() - return render_template('index.html', events=events) + #events = get_json.main() + #return render_template('index.html', events=events) -@app.route(json_url) -def summary(): - x = "meme" - return x + return render_template('index.html') + +@app.route("/events") +def server_json(): + with open("events.json") as event_json: + return json.load(event_json) @app.route(webhook_update_url, methods=['GET', 'POST']) def update():