Allow customizing the refresh rate
This commit is contained in:
parent
a71821aeb0
commit
dabaf2eab5
2 changed files with 18 additions and 14 deletions
11
app.py
11
app.py
|
@ -1,5 +1,5 @@
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from dateutil.parser import parse as dateparse
|
from dateutil.parser import parse as dateparse
|
||||||
from pytz import reference
|
from pytz import reference
|
||||||
import flask
|
import flask
|
||||||
|
@ -9,6 +9,11 @@ app = flask.Flask(__name__)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
try:
|
||||||
|
refresh = int(flask.request.args.get("refresh", "300"))
|
||||||
|
except ValueError:
|
||||||
|
refresh = 300
|
||||||
|
|
||||||
url = flask.request.args.get("apiurl", "")
|
url = flask.request.args.get("apiurl", "")
|
||||||
if url:
|
if url:
|
||||||
json = requests.get(url).json()
|
json = requests.get(url).json()
|
||||||
|
@ -20,10 +25,14 @@ def index():
|
||||||
else:
|
else:
|
||||||
listings = []
|
listings = []
|
||||||
|
|
||||||
|
now = datetime.now()
|
||||||
return flask.render_template(
|
return flask.render_template(
|
||||||
"marktplaats.html",
|
"marktplaats.html",
|
||||||
listings=listings,
|
listings=listings,
|
||||||
|
refresh=refresh,
|
||||||
dateparse=dateparse,
|
dateparse=dateparse,
|
||||||
|
now=now,
|
||||||
|
next=now + timedelta(seconds=refresh),
|
||||||
tz=reference.LocalTimezone(),
|
tz=reference.LocalTimezone(),
|
||||||
apiurl=url,
|
apiurl=url,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
{##}
|
{##}
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="refresh" content="60">
|
<meta http-equiv="refresh" content="{{refresh}}">
|
||||||
|
<title>
|
||||||
|
{{listings[0].title}}
|
||||||
|
({{dateparse(listings[0].date).astimezone(tz).strftime("%H:%M")}})
|
||||||
|
</title>
|
||||||
<style>
|
<style>
|
||||||
main {
|
main {
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
|
@ -9,15 +13,6 @@
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
form {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type=text] {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 1em;
|
font-size: 1em;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +43,8 @@
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<form method="get">
|
<form method="get">
|
||||||
URL:
|
URL: <input type="text" name="apiurl" value="{{apiurl}}" style="width: 530px" placeholder="https://www.marktplaats.nl/lrp/api/search?..."><br />
|
||||||
<input type="text" name="apiurl" value="{{apiurl}}" placeholder="https://www.marktplaats.nl/lrp/api/search?...">
|
Refresh: <input type="text" name="refresh" value="{{refresh}}" style="width: 100px; text-align: right"> seconds (last update: {{now.strftime("%H:%M:%S")}}; next update: {{next.strftime("%H:%M:%S")}})<br />
|
||||||
<input type="submit" value="h">
|
<input type="submit" value="h">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -63,7 +58,7 @@
|
||||||
{{listing.priceInfo.priceType}}
|
{{listing.priceInfo.priceType}}
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
{{dateparse(listing.date).astimezone(tz).strftime("%Y-%m-%d %H:%M")}}
|
{{dateparse(listing.date).astimezone(tz).strftime("%Y-%m-%d %H:%M:%S")}}
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
{{listing.location.cityName}} ({{listing.location.distanceMeters // 1000}} km)
|
{{listing.location.cityName}} ({{listing.location.distanceMeters // 1000}} km)
|
||||||
|
|
Loading…
Reference in a new issue