|
|
|
"""This is the main flask library page"""
|
|
|
|
|
|
|
|
|
|
|
|
import flask
|
|
|
|
from requests import get
|
|
|
|
from icalendar import Calendar
|
|
|
|
import datetime
|
|
|
|
from flask import render_template
|
|
|
|
from rnrfeed.rnrfeeder import getevents, getlatestevent
|
|
|
|
from uploadform import PublicationForm
|
|
|
|
from csvparser.csvparser import (
|
|
|
|
getlicenses,
|
|
|
|
getpublications,
|
|
|
|
gettypes,
|
|
|
|
getyears,
|
|
|
|
getfullpublication,
|
|
|
|
)
|
|
|
|
from flask_wtf.csrf import CSRFProtect
|
|
|
|
|
|
|
|
|
|
|
|
csrf = CSRFProtect()
|
|
|
|
APP = flask.Flask(__name__, static_folder="static")
|
|
|
|
APP.config['SECRET_KEY'] = 'ty4425hk54a21eee5719b9s9df7sdfklx'
|
|
|
|
csrf.init_app(APP)
|
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/")
|
|
|
|
def index():
|
|
|
|
"""Main route, shows all the books and you can filter them, a bit"""
|
|
|
|
pubtypes = gettypes()
|
|
|
|
pubyears = getyears()
|
|
|
|
publicenses = getlicenses()
|
|
|
|
publicatons = getpublications()
|
|
|
|
template = render_template(
|
|
|
|
"index.html",
|
|
|
|
publications=publicatons,
|
|
|
|
pubtypes=pubtypes,
|
|
|
|
pubyears=pubyears,
|
|
|
|
publicenses=publicenses,
|
|
|
|
)
|
|
|
|
return template
|
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/upload")
|
|
|
|
def upload():
|
|
|
|
uploadform = PublicationForm()
|
|
|
|
return render_template("upload.html", uploadform=uploadform)
|
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/<publicationID>")
|
|
|
|
def show_book(publicationID):
|
|
|
|
"""route for a publication, still needs to be made"""
|
|
|
|
fullpublication = getfullpublication(publicationID)
|
|
|
|
# parse csv, render template with full list.
|
|
|
|
return render_template("publication.html", fullpublication=fullpublication)
|
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/pastevents")
|
|
|
|
def pastevents():
|
|
|
|
"""show past events and book recommendations"""
|
|
|
|
events = getevents()
|
|
|
|
return render_template("pastevents.html", events=events)
|
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/upcoming")
|
|
|
|
def latestevent():
|
|
|
|
"""show upcoming or latest event and book recommendations"""
|
|
|
|
event = getlatestevent()
|
|
|
|
return render_template("upcomingevent.html", event=event)
|
|
|
|
|
|
|
|
|
|
|
|
@APP.context_processor
|
|
|
|
def upcoming_or_latest():
|
|
|
|
upcoming = True
|
|
|
|
ics = get("https://varia.zone/events.ics").text
|
|
|
|
gcal = Calendar.from_ical(ics)
|
|
|
|
eventtimes = [
|
|
|
|
c.get("dtstart").dt for c in gcal.walk()
|
|
|
|
if c.name == "VEVENT"
|
|
|
|
and "Read & Repair" in c.get("summary")
|
|
|
|
]
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
eventtimes.sort()
|
|
|
|
eventtimes.reverse()
|
|
|
|
if now > eventtimes[0]:
|
|
|
|
upcoming = False
|
|
|
|
|
|
|
|
return dict(upcoming=upcoming)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
APP.debug = True
|
|
|
|
APP.run(port=5000)
|