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=
|
||||
URL=
|
||||
TIMEZONE=
|
||||
JSON-URL=
|
||||
WEBHOOK-URL=
|
|
@ -72,15 +72,11 @@
|
|||
minute: '2-digit',
|
||||
hour12: false
|
||||
},
|
||||
events: [
|
||||
{% for event in events %}
|
||||
{
|
||||
title: '{{ event.title }}',
|
||||
start: '{{ event.start }}',
|
||||
end: '{{event.end}}'
|
||||
failure: function() {
|
||||
alert('There was an error while fetching events from /events! ');
|
||||
},
|
||||
{% endfor %}
|
||||
]
|
||||
events: '/events',
|
||||
|
||||
});
|
||||
|
||||
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"}]
|
|
@ -26,11 +26,12 @@ 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):
|
||||
|
@ -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()
|
||||
|
|
17
main.py
17
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():
|
||||
|
|
Loading…
Reference in a new issue