Add a fetch button to source list

This commit is contained in:
Tim Van Baak 2024-09-21 14:13:00 -07:00
parent 4947ce56c6
commit 92a10c5ca8
2 changed files with 28 additions and 1 deletions

View File

@ -20,7 +20,14 @@ from flask import (
from intake.core import intake_data_dir from intake.core import intake_data_dir
from intake.crontab import update_crontab_entries 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 # Globals
app = Flask(__name__) app = Flask(__name__)
@ -381,6 +388,22 @@ def _parse_channels_config(config_str: str):
return (None, parsed) return (None, parsed)
@app.post("/fetch/<string:source_name>")
@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") @app.post("/add")
@auth_check @auth_check
def add_item(): def add_item():

View File

@ -37,6 +37,9 @@ summary:focus {
.intake-sources td { .intake-sources td {
padding-block: 0.4em; padding-block: 0.4em;
} }
.intake-sources form {
margin: 0
}
</style> </style>
</head> </head>
<body> <body>
@ -78,6 +81,7 @@ summary:focus {
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
</td> </td>
<td><form id="{{ source.source_name }}"><button type="submit" formmethod=post formaction="{{ url_for('fetch', source_name=source.source_name) }}" />fetch</button></form></td>
<td>(<a href="{{ url_for('source_edit', name=source.source_name) }}">edit</a>)</td> <td>(<a href="{{ url_for('source_edit', name=source.source_name) }}">edit</a>)</td>
<td><a href="{{ url_for('source_feed', name=source.source_name) }}">{{ source.source_name|safe }}</a></td> <td><a href="{{ url_for('source_feed', name=source.source_name) }}">{{ source.source_name|safe }}</a></td>
</tr> </tr>