Re-implement punt with HTTP PATCH

This commit is contained in:
Tim Van Baak 2023-05-29 21:11:04 -07:00
parent b8c7a13505
commit dbfbd60f7f
2 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime, timedelta
from pathlib import Path from pathlib import Path
import os import os
import time
from flask import Flask, render_template, request, jsonify, abort, redirect, url_for 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"]}) return jsonify({"active": item["active"]})
@app.patch("/item/<string:source_name>/<string:item_id>")
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(): def wsgi():
# init_default_logging() # init_default_logging()
return app return app

View File

@ -72,12 +72,12 @@ var deactivate = function (source, itemid) {
}); });
}; };
var punt = function (source, itemid) { var punt = function (source, itemid) {
fetch('/punt/', { fetch(`/item/${source}/${itemid}`, {
method: 'POST', method: 'PATCH',
headers: { headers: {
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
}, },
body: JSON.stringify({source: source, itemid: itemid}), body: JSON.stringify({tts: "+1"}),
}) })
.then(response => response.json()) .then(response => response.json())
.then(function (data) { .then(function (data) {