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
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil.parser import parse as dateparse
|
||||
from pytz import reference
|
||||
import flask
|
||||
|
@ -9,6 +9,11 @@ app = flask.Flask(__name__)
|
|||
|
||||
@app.route("/")
|
||||
def index():
|
||||
try:
|
||||
refresh = int(flask.request.args.get("refresh", "300"))
|
||||
except ValueError:
|
||||
refresh = 300
|
||||
|
||||
url = flask.request.args.get("apiurl", "")
|
||||
if url:
|
||||
json = requests.get(url).json()
|
||||
|
@ -20,10 +25,14 @@ def index():
|
|||
else:
|
||||
listings = []
|
||||
|
||||
now = datetime.now()
|
||||
return flask.render_template(
|
||||
"marktplaats.html",
|
||||
listings=listings,
|
||||
refresh=refresh,
|
||||
dateparse=dateparse,
|
||||
now=now,
|
||||
next=now + timedelta(seconds=refresh),
|
||||
tz=reference.LocalTimezone(),
|
||||
apiurl=url,
|
||||
)
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
{##}
|
||||
<html>
|
||||
<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>
|
||||
main {
|
||||
font-family: sans-serif;
|
||||
|
@ -9,15 +13,6 @@
|
|||
margin: 0 auto;
|
||||
}
|
||||
|
||||
form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
input[type=text] {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
@ -48,8 +43,8 @@
|
|||
<body>
|
||||
<main>
|
||||
<form method="get">
|
||||
URL:
|
||||
<input type="text" name="apiurl" value="{{apiurl}}" placeholder="https://www.marktplaats.nl/lrp/api/search?...">
|
||||
URL: <input type="text" name="apiurl" value="{{apiurl}}" style="width: 530px" placeholder="https://www.marktplaats.nl/lrp/api/search?..."><br />
|
||||
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">
|
||||
</form>
|
||||
|
||||
|
@ -63,7 +58,7 @@
|
|||
{{listing.priceInfo.priceType}}
|
||||
<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>
|
||||
|
||||
{{listing.location.cityName}} ({{listing.location.distanceMeters // 1000}} km)
|
||||
|
|
Loading…
Reference in a new issue