38 lines
898 B
Python
38 lines
898 B
Python
import requests
|
|
from datetime import datetime, timedelta
|
|
from dateutil.parser import parse as dateparse
|
|
from pytz import reference
|
|
import flask
|
|
|
|
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()
|
|
listings = [
|
|
listing
|
|
for listing in json["listings"]
|
|
if listing["priorityProduct"] == "NONE"
|
|
]
|
|
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,
|
|
)
|