This commit is contained in:
Aeris 2021-07-02 19:38:26 +02:00
parent 5d65f9cc73
commit a60781405b

View file

@ -7,6 +7,70 @@ import requests
import datetime import datetime
import os import os
def fetchThalia():
# fetching the html page
headers = { 'user-agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36',
'accept-encoding': 'gzip, deflate',
'accept-language': 'en-US,en;q=0.5',
'cookie': 'GESCHICHTENENTDECKERAB=false; SPIELWARENVISAB=false; SFORMAT_BUCH=SMO2cmJ1Y2gtRG93bmxvYWRfTVAz; gcor="SIDYN1yqhjMJDyVK45QHJCdvQAAAKQ"; ab_bucket=9; ab_container=3; FDCSESSION=7D7CF1AF51E48F70EF1EF81105D0C25C.shoptc6; KUNDE_LAYOUT=FLAT; WARENKORB-XSRF-TOKEN=97a702ea-5ea1-4431-902f-616cd350f417; abokaufen-XSRF-TOKEN=aec0b4e1-6fb9-4965-82f4-b5856a471c27; affiliate-XSRF-TOKEN=59ebc500-e4e0-486f-805e-0e375d810ca1; SUCHE_LAYOUT=FLAT; club=KEIN_MITGLIED'
}
response = requests.get('https://www.thalia.de/bz/hoerbuch-downloads-neuheiten/201567-201859-213891/?sort=sfed&filterIM_ABO_VERFUEGBAR_HBDL=IAV&ajax=false&asn=true&allayout=FLAT', headers=headers)
doc = response.text
# getting the items
tree = etree.HTML(doc)
items = tree.xpath("//ul[contains(concat(' ', @class, ' '), 'suchergebnis-liste')]/li")
# creating a feed
feed = feedgenerator.Rss201rev2Feed(title="Foo",
link="https://rss.eris.cc/thalia/new",
description="Thalia Neuerscheinungen aus der Kategorie Hoerbuecher",
language="de")
# for each line in the table
for i in items:
print(i)
# getting the identifier
ids = i.xpath('@data-ean')
post_id = 'empty' if len(ids) == 0 else ids[0]
# getting the link
links = i.xpath('a/@href')
link = 'empty' if len(links) == 0 else 'https://www.thalia.de' + links[0]
# getting the description
descriptions = i.xpath('ul/li/p[3]/text()')
description = 'empty' if len(descriptions) == 0 else descriptions[0]
# getting the description
descriptions = i.xpath('ul/li/a/@product-price')
if len(descriptions) > 0:
description += ", Preis: " + descriptions[0]
# getting the title
titles = i.xpath('section/h3/text()')
title = 'empty' if len(titles) == 0 else titles[0]
#date
authors = i.xpath('/li/section/ul/li')
author = ''
for j in authors:
author += j.xpath('/a/text()')[0]
feed.add_item(
title=title,
link=link,
description=description,
unique_id=post_id,
author=author
)
return(bytes(feed.writeString('utf-8'),'utf-8'))
# f = open("out.xml", "a")
# f.write(feed.writeString('utf-8'))
# f.close()
def fetchBoerse(): def fetchBoerse():
@ -26,9 +90,9 @@ def fetchBoerse():
# creating a feed # creating a feed
feed = feedgenerator.Rss201rev2Feed(title="Foo", feed = feedgenerator.Rss201rev2Feed(title="Foo",
link="https://foo/bar", link="https://rss.eris.cc/boerse/audiobooks",
description="Foo", description="Aktuelle Releases aus der Boerse",
language="fr") language="de")
# for each line in the table # for each line in the table
for i in items: for i in items:
@ -82,6 +146,11 @@ class Handler(BaseHTTPRequestHandler):
self.send_header('Content-type','application/rss+xml; charset=utf8') self.send_header('Content-type','application/rss+xml; charset=utf8')
self.end_headers() self.end_headers()
self.wfile.write(fetchBoerse()) self.wfile.write(fetchBoerse())
elif self.path == '/thalia/new':
self.send_response(200)
self.send_header('Content-type','application/rss+xml; charset=utf8')
self.end_headers()
self.wfile.write(fetchThalia())
else: else:
self.send_response(404) self.send_response(404)
self.send_header('Content-type','text/html; charset=utf8') self.send_header('Content-type','text/html; charset=utf8')
@ -90,3 +159,4 @@ class Handler(BaseHTTPRequestHandler):
server = HTTPServer(('0.0.0.0', 3000), Handler) server = HTTPServer(('0.0.0.0', 3000), Handler)
server.serve_forever() server.serve_forever()