Skip to content

Commit

Permalink
Add kleinanzeigen plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Rumrobot committed Feb 9, 2024
1 parent 3468458 commit 047db1a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Name | URL
--- | ---
Den Blå Avis | https://dba.dk
eBay | https://ebay.com
Kleinanzeigen | https://kleinanzeigen.de

It uses the [Discord Webhook API](https://discord.com/developers/docs/resources/webhook) to send a message to a channel of your choice.

Expand Down Expand Up @@ -33,6 +34,7 @@ Each plugin has the following fields:
- `name`: The name of the plugin. This can be one of the following:
- [`dba`](#dba)
- [`ebay`](#ebay)
- [`kleinanzeigen`](#kleinanzeigen)
- `search_url`: The URL of the search query you want to monitor. Plugin specific.
- `webhook_url`: The URL of the Discord Webhook you want to send the message to.
- `message_content`: The message you want to be sent to the Discord channel alongside the listings.
Expand All @@ -51,3 +53,6 @@ It can also be a normal search query, for example: `https://www.dba.dk/soeg/?soe

#### eBay
For the `ebay` plugin, the `search_url` field should be the URL of the search query you want to monitor. For example, if you want to monitor new analogue cameras, the `search_url` field could be `https://www.ebay.com/sch/i.html?_nkw=analog+camera&_sop=10`. This means that the search query is `analog camera` and the listings are sorted by the newest first.

#### Kleinanzeigen
For the `kleinanzeigen` plugin, the `search_url` field should be the URL of the search query you want to monitor. For example, if you want to monitor new analogue cameras, the `search_url` field could be `https://www.kleinanzeigen.de/s-analog-kamera/k0`.
6 changes: 5 additions & 1 deletion plugins/ebay.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ async def fetch_listings(self):
listings = []
for item in list_items:
if "s-item" in item.get("class", []):
url = item.find("a", {"class": "s-item__link"}).get("href", "").split("?")[0]
url = (
item.find("a", {"class": "s-item__link"})
.get("href", "")
.split("?")[0]
)
name = item.find("div", {"class": "s-item__title"}).text
image_url = item.find("img").get("src")
price = item.find("span", {"class": "s-item__price"}).text
Expand Down
56 changes: 56 additions & 0 deletions plugins/kleinanzeigen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import html
import json
from aiohttp import ClientSession
from bs4 import BeautifulSoup
from .common import MarketplaceListing, MarketplacePlugin


class Plugin(MarketplacePlugin):
def __init__(self, session: ClientSession, search_url: str) -> None:
name = "Kleinanzeigen"
color = 0xB5E941
super().__init__(name, color, session, search_url)

async def fetch_listings(self):
existing_listings = await self.get_saved_listings()
try:
response = await self.session.get(self.search_url)
except Exception as e:
self.log(f"Error when requesting site: {e}")
return []
text = await response.text()

# Parse HTML
soup = BeautifulSoup(text, "html.parser")
list_items = soup.find_all("li")

listings = []

for item in list_items:
article = item.find("article", class_="aditem")
if article:
name = article.find("h2").text.strip()
if article.find("img"):
image_url = (
article.find("img").get("src", "").split("?")[0]
+ "?rule=$_57.JPG"
)
else:
image_url = "https://i.imgur.com/8Eixst2.jpeg"
url = "https://kleinanzeigen.de" + article["data-href"]
price = (
article.find(
"p", class_="aditem-main--middle--price-shipping--price"
)
.text.strip()
.split(" €")[0]
.replace(".", "")
)

if url not in [listing.url for listing in existing_listings]:
listings.append(
MarketplaceListing(name, image_url, url, f"{int(price):,d} €")
)

await self.save_listings(existing_listings + listings)
return listings # The new ones
2 changes: 1 addition & 1 deletion static/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"properties": {
"name": {
"type": "string",
"enum": ["dba", "ebay"],
"enum": ["dba", "ebay", "klenanzeigen"],
"default": "dba",
"title": "The name of the plugin."
},
Expand Down

0 comments on commit 047db1a

Please sign in to comment.