This commit is contained in:
Sijmen 2020-01-29 22:05:28 +01:00
commit 38a50d04c6
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
5 changed files with 122 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
__pycache__/
.mypy_cache

7
README.md Normal file
View file

@ -0,0 +1,7 @@
First do `pip install --user -r requirements.txt` (or use a virtual env or
something, idc). Then do `flask run`. That should be about it.
Grab the API call from inspect element and stick it in the input box.
If Marktplaats gets mad at you for using this for some reason, don't get mad at
me. Use at your own risk.

29
app.py Normal file
View file

@ -0,0 +1,29 @@
import requests
from datetime import datetime
from dateutil.parser import parse as dateparse
from pytz import reference
import flask
app = flask.Flask(__name__)
@app.route("/")
def index():
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 = []
return flask.render_template(
"marktplaats.html",
listings=listings,
dateparse=dateparse,
tz=reference.LocalTimezone(),
apiurl=url,
)

3
requirements.txt Normal file
View file

@ -0,0 +1,3 @@
pytz~=2019.3
Flask~=1.1.1
python-dateutil~=2.8.1

View file

@ -0,0 +1,81 @@
{##}
<html>
<head>
<meta http-equiv="refresh" content="60">
<style>
main {
font-family: sans-serif;
max-width: 600px;
margin: 0 auto;
}
form {
display: flex;
align-items: center;
}
input[type=text] {
flex: 1;
}
h1 {
font-size: 1em;
}
.listing {
display: flex;
padding: 8px;
border-bottom: 1px solid rgba(0, 0, 0, .12);
box-sizing: border-box;
}
.listing:hover {
background-color: rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0);
}
.listing > div:first-child {
flex: 1;
}
a {
color: inherit;
text-decoration: none;
}
</style>
</head>
<body>
<main>
<form method="get">
URL:
<input type="text" name="apiurl" value="{{apiurl}}" placeholder="https://www.marktplaats.nl/lrp/api/search?...">
<input type="submit" value="h">
</form>
{% for listing in listings %}
<a href="https://marktplaats.nl{{listing.vipUrl}}">
<div class="listing">
<div>
<h1>{{listing.title}}</h1>
<p>
&euro;{{ "{:.2f}".format(listing.priceInfo.priceCents / 100) }}
{{listing.priceInfo.priceType}}
<br>
{{dateparse(listing.date).astimezone(tz).strftime("%Y-%m-%d %H:%M")}}
<br>
{{listing.location.cityName}} ({{listing.location.distanceMeters // 1000}} km)
</p>
</div>
{% for image in listing.imageUrls %}
<img src="{{ image }}" />
{% endfor %}
</div>
</a>
{% endfor %}
</main>
</body>
</html>