2021-02-16 23:26:03 +01:00
|
|
|
import flask
|
2021-02-23 13:25:58 +01:00
|
|
|
import flask_apscheduler
|
2021-02-16 23:26:03 +01:00
|
|
|
import feedtools
|
2021-02-17 21:21:23 +01:00
|
|
|
import json
|
2021-02-16 23:26:03 +01:00
|
|
|
|
|
|
|
APP = flask.Flask(__name__,
|
|
|
|
static_url_path="",
|
|
|
|
static_folder="static",
|
|
|
|
template_folder="templates")
|
|
|
|
|
2021-02-23 13:25:58 +01:00
|
|
|
# Initialize Flask-APScheduler
|
|
|
|
# https://github.com/viniciuschiele/flask-apscheduler
|
|
|
|
# Thanks Crunk for pointing to this extention!
|
|
|
|
scheduler = flask_apscheduler.APScheduler()
|
|
|
|
scheduler.api_enabled = False
|
|
|
|
scheduler.init_app(APP)
|
|
|
|
scheduler.start()
|
|
|
|
|
|
|
|
@scheduler.task('interval', id='update', minutes=10)
|
|
|
|
def update():
|
|
|
|
print('Updating the Multifeeder!')
|
|
|
|
feedtools.update()
|
|
|
|
|
2021-02-16 23:26:03 +01:00
|
|
|
@APP.route("/")
|
|
|
|
def index():
|
|
|
|
db = feedtools.load()
|
|
|
|
template = flask.render_template(
|
|
|
|
"index.html",
|
2021-02-17 21:21:23 +01:00
|
|
|
db=db,
|
2021-02-16 23:26:03 +01:00
|
|
|
)
|
|
|
|
return template
|
|
|
|
|
2021-02-17 21:21:23 +01:00
|
|
|
@APP.route("/API/latest/<num>")
|
|
|
|
def latest(num):
|
2022-02-21 17:47:09 +01:00
|
|
|
feed = feedtools.latest(num)
|
|
|
|
if flask.request.values.get("format") == 'md':
|
|
|
|
response_data = feedtools.md(feed)
|
|
|
|
mimetype_data = 'text/plain'
|
|
|
|
else:
|
|
|
|
response_data = json.dumps(feed)
|
|
|
|
mimetype_data = 'application/json'
|
2021-02-16 23:26:03 +01:00
|
|
|
|
2022-02-21 17:47:09 +01:00
|
|
|
return APP.response_class(
|
|
|
|
response=response_data,
|
|
|
|
status=200,
|
|
|
|
mimetype=mimetype_data
|
|
|
|
)
|
|
|
|
|
|
|
|
@APP.route("/API/today")
|
2021-02-16 23:26:03 +01:00
|
|
|
def today():
|
2022-02-21 17:47:09 +01:00
|
|
|
feed = feedtools.today()
|
|
|
|
if flask.request.values.get("format") == 'md':
|
|
|
|
response_data = feedtools.md(feed)
|
|
|
|
mimetype_data = 'text/plain'
|
|
|
|
else:
|
|
|
|
response_data = json.dumps(feed)
|
|
|
|
mimetype_data = 'application/json'
|
|
|
|
return APP.response_class(
|
|
|
|
response=response_data,
|
|
|
|
status=200,
|
|
|
|
mimetype=mimetype_data
|
|
|
|
)
|
2021-02-16 23:26:03 +01:00
|
|
|
|
|
|
|
@APP.route("/API/past/<days>")
|
|
|
|
def past(days):
|
2022-02-21 17:47:09 +01:00
|
|
|
feed = feedtools.past(days)
|
|
|
|
if flask.request.values.get("format") == 'md':
|
|
|
|
response_data = feedtools.md(feed)
|
|
|
|
mimetype_data = 'text/plain'
|
|
|
|
else:
|
|
|
|
response_data = json.dumps(feed)
|
|
|
|
mimetype_data = 'application/json'
|
|
|
|
return APP.response_class(
|
|
|
|
response=response_data,
|
|
|
|
status=200,
|
|
|
|
mimetype=mimetype_data
|
|
|
|
)
|
2021-02-16 23:26:03 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-02-17 21:21:23 +01:00
|
|
|
feedtools.update()
|
2021-02-16 23:26:03 +01:00
|
|
|
APP.debug = True
|
|
|
|
APP.run(port=5678)
|
|
|
|
|