From dbfbd60f7fd90556fff74eea47f22fe3bc9e7ce4 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 29 May 2023 21:11:04 -0700 Subject: [PATCH] Re-implement punt with HTTP PATCH --- intake/app.py | 17 ++++++++++++++++- intake/templates/feed.jinja2 | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/intake/app.py b/intake/app.py index 390cca8..5a5eefc 100644 --- a/intake/app.py +++ b/intake/app.py @@ -1,6 +1,7 @@ -from datetime import datetime +from datetime import datetime, timedelta from pathlib import Path import os +import time from flask import Flask, render_template, request, jsonify, abort, redirect, url_for @@ -94,6 +95,20 @@ def deactivate(source_name, item_id): return jsonify({"active": item["active"]}) +@app.patch("/item//") +def update(source_name, item_id): + source = LocalSource(intake_data_dir(), source_name) + item = source.get_item(item_id) + params = request.get_json() + if "tts" in params: + tomorrow = datetime.now() + timedelta(days=1) + morning = datetime(tomorrow.year, tomorrow.month, tomorrow.day, 6, 0, 0) + til_then = morning.timestamp() - item["created"] + item["tts"] = til_then + source.save_item(item) + return jsonify(item) + + def wsgi(): # init_default_logging() return app diff --git a/intake/templates/feed.jinja2 b/intake/templates/feed.jinja2 index 053b747..0c219ed 100644 --- a/intake/templates/feed.jinja2 +++ b/intake/templates/feed.jinja2 @@ -72,12 +72,12 @@ var deactivate = function (source, itemid) { }); }; var punt = function (source, itemid) { - fetch('/punt/', { - method: 'POST', + fetch(`/item/${source}/${itemid}`, { + method: 'PATCH', headers: { 'Content-Type': 'application/json; charset=UTF-8', }, - body: JSON.stringify({source: source, itemid: itemid}), + body: JSON.stringify({tts: "+1"}), }) .then(response => response.json()) .then(function (data) {