You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
import json
|
|
import os
|
|
|
|
import flask_apscheduler
|
|
import tomli
|
|
from flask import Flask
|
|
|
|
from column import Column
|
|
from simplejsonstorage import SimpleJsonStorage
|
|
|
|
|
|
def create_app():
|
|
APP = Flask(__name__)
|
|
scheduler = flask_apscheduler.APScheduler()
|
|
scheduler.api_enabled = False
|
|
scheduler.init_app(APP)
|
|
scheduler.start()
|
|
json_file = SimpleJsonStorage(
|
|
os.path.join("data", "feeds.json"), os.path.join("data", "feeds.log")
|
|
)
|
|
update_feeds(json_file)
|
|
|
|
@scheduler.task("interval", id="update", minutes=10)
|
|
def update():
|
|
update_feeds(json_file)
|
|
|
|
return APP
|
|
|
|
|
|
def update_feeds(json_file):
|
|
with open("columns.toml", "rb") as f:
|
|
column_dict = tomli.load(f)
|
|
|
|
columns_file = column_dict["column"]
|
|
columns = {}
|
|
for column_from_file in columns_file:
|
|
title = column_from_file["title"]
|
|
column = Column(title, column_from_file["urls"])
|
|
|
|
if "limit" in column_from_file:
|
|
column.set_limit(column_from_file["limit"])
|
|
if "sort_order" in column_from_file:
|
|
column.set_sort_order(column_from_file["sort_order"])
|
|
if "tag_filter" in column_from_file:
|
|
column.set_tag_filter(column_from_file["tag_filter"])
|
|
|
|
column.load_content_from_feeds()
|
|
columns[title] = column.__dict__
|
|
json_file.update(columns)
|
|
|