Add subfeed routes
This commit is contained in:
parent
9843fd93c4
commit
27e04e601a
@ -4,10 +4,10 @@ import os
|
||||
import traceback
|
||||
|
||||
# Third party imports
|
||||
from flask import Flask, render_template, request, jsonify, abort
|
||||
from flask import Flask, render_template, request, jsonify, abort, redirect, url_for
|
||||
|
||||
# Application imports
|
||||
from inquisitor.configs import logger, DUNGEON_PATH, CACHE_PATH
|
||||
from inquisitor.configs import logger, DUNGEON_PATH, CACHE_PATH, subfeeds
|
||||
from inquisitor import sources, loader, timestamp
|
||||
|
||||
# Globals
|
||||
@ -27,6 +27,19 @@ def datetimeformat(value):
|
||||
|
||||
@app.route("/")
|
||||
def root():
|
||||
return redirect(url_for('feed'))
|
||||
|
||||
@app.route("/feed/")
|
||||
def feed():
|
||||
return feed_for_sources(source_names=None)
|
||||
|
||||
@app.route("/feed/<string:feed_name>/")
|
||||
def subfeed(feed_name):
|
||||
if feed_name not in subfeeds:
|
||||
return abort(404)
|
||||
return feed_for_sources(subfeeds[feed_name])
|
||||
|
||||
def feed_for_sources(source_names):
|
||||
# Determine exclusion filters
|
||||
filters = []
|
||||
wl_param = request.args.get('only')
|
||||
@ -40,7 +53,7 @@ def root():
|
||||
|
||||
# Get all active+filtered items and all active tags
|
||||
total = 0
|
||||
items, errors = loader.load_active_items()
|
||||
items, errors = loader.load_active_items(source_names)
|
||||
active_items = []
|
||||
active_tags = {}
|
||||
for item in items:
|
||||
|
@ -173,7 +173,7 @@ def command_feed(args):
|
||||
from inquisitor import loader
|
||||
from inquisitor import timestamp
|
||||
|
||||
items, errors = loader.load_active_items()
|
||||
items, errors = loader.load_active_items(source_names=None)
|
||||
if not items and not errors:
|
||||
print("Feed is empty")
|
||||
return 0
|
||||
|
@ -1,4 +1,4 @@
|
||||
from .resolver import data_path as DUNGEON_PATH
|
||||
from .resolver import source_path as SOURCES_PATH
|
||||
from .resolver import cache_path as CACHE_PATH
|
||||
from .resolver import logger, add_logging_handler, init_default_logging
|
||||
from .resolver import logger, add_logging_handler, init_default_logging, subfeeds
|
@ -2,7 +2,7 @@ import os
|
||||
import json
|
||||
|
||||
|
||||
from inquisitor.configs import DUNGEON_PATH
|
||||
from inquisitor.configs import DUNGEON_PATH, logger
|
||||
from inquisitor import error
|
||||
from inquisitor import timestamp
|
||||
|
||||
@ -152,28 +152,35 @@ def load_items(source_name):
|
||||
errors.append(filename)
|
||||
return items, errors
|
||||
|
||||
def load_active_items():
|
||||
|
||||
def load_active_items(source_names):
|
||||
"""
|
||||
Returns a list of active items and a list of unreadable items.
|
||||
Returns a list of active items and a list of unreadable items. If
|
||||
`source_names` is defined, load only from sources in that list.
|
||||
"""
|
||||
items = []
|
||||
errors = []
|
||||
now = timestamp.now()
|
||||
for cell_name in os.listdir(DUNGEON_PATH):
|
||||
cell_path = os.path.join(DUNGEON_PATH, cell_name)
|
||||
for filename in os.listdir(cell_path):
|
||||
if filename.endswith('.item'):
|
||||
try:
|
||||
item = load_item(cell_name, filename[:-5])
|
||||
# The time-to-show field hides items until an expiry date.
|
||||
if 'tts' in item:
|
||||
tts_date = item['created'] + item['tts']
|
||||
if now < tts_date:
|
||||
continue
|
||||
# Don't show inactive items
|
||||
if not item['active']:
|
||||
check_list = source_names or os.listdir(DUNGEON_PATH)
|
||||
for source_name in check_list:
|
||||
source_path = os.path.join(DUNGEON_PATH, source_name)
|
||||
if not os.path.isdir(source_path):
|
||||
logger.warning(f'Skipping nonexistent source {source_name}')
|
||||
continue
|
||||
for filename in os.listdir(source_path):
|
||||
if not filename.endswith('.item'):
|
||||
continue
|
||||
try:
|
||||
item = load_item(source_name, filename[:-5])
|
||||
# The time-to-show field hides items until an expiry date.
|
||||
if 'tts' in item:
|
||||
tts_date = item['created'] + item['tts']
|
||||
if now < tts_date:
|
||||
continue
|
||||
items.append(item)
|
||||
except Exception:
|
||||
errors.append(filename)
|
||||
# Don't show inactive items
|
||||
if not item['active']:
|
||||
continue
|
||||
items.append(item)
|
||||
except Exception:
|
||||
errors.append(filename)
|
||||
return items, errors
|
||||
|
Loading…
Reference in New Issue
Block a user