From 92a10c5ca87668774a84add7d1f59d9d5a0f1842 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sat, 21 Sep 2024 14:13:00 -0700 Subject: [PATCH] Add a fetch button to source list --- intake/app.py | 25 ++++++++++++++++++++++++- intake/templates/home.jinja2 | 4 ++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/intake/app.py b/intake/app.py index 328724d..57a2274 100644 --- a/intake/app.py +++ b/intake/app.py @@ -20,7 +20,14 @@ from flask import ( from intake.core import intake_data_dir from intake.crontab import update_crontab_entries -from intake.source import LocalSource, execute_action, Item +from intake.source import ( + LocalSource, + execute_action, + Item, + fetch_items, + update_items, +) +from intake.types import InvalidConfigException, SourceUpdateException # Globals app = Flask(__name__) @@ -381,6 +388,22 @@ def _parse_channels_config(config_str: str): return (None, parsed) +@app.post("/fetch/") +@auth_check +def fetch(source_name: str): + data_path: Path = current_app.config["INTAKE_DATA"] + source = LocalSource(data_path, source_name) + + try: + items = fetch_items(source) + update_items(source, items) + return f"Update returned {len(items)} items" + except InvalidConfigException as ex: + abort(500, f"Could not fetch {source_name}:\n{ex}") + except SourceUpdateException as ex: + abort(500, f"Error updating source {source_name}:\n{ex}") + + @app.post("/add") @auth_check def add_item(): diff --git a/intake/templates/home.jinja2 b/intake/templates/home.jinja2 index 4f06ec3..0295479 100644 --- a/intake/templates/home.jinja2 +++ b/intake/templates/home.jinja2 @@ -37,6 +37,9 @@ summary:focus { .intake-sources td { padding-block: 0.4em; } +.intake-sources form { + margin: 0 +} @@ -78,6 +81,7 @@ summary:focus { {%- endif -%} {%- endfor -%} +
(edit) {{ source.source_name|safe }}