-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from Lukas0907/next
Update TU Wien, diepresse, derstandard, add delinski
- Loading branch information
Showing
7 changed files
with
125 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.. _spider_delinski.at: | ||
|
||
delinski.at | ||
----------- | ||
Newest restaurants in Wien bookable at `Delinski <https://delinski.at>`_. | ||
|
||
Configuration | ||
~~~~~~~~~~~~~ | ||
Add ``delinski.at`` to the list of spiders: | ||
|
||
.. code-block:: ini | ||
# List of spiders to run by default, one per line. | ||
spiders = | ||
delinski.at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import json | ||
import re | ||
from datetime import datetime, timedelta | ||
|
||
import scrapy | ||
|
||
from feeds.loaders import FeedEntryItemLoader | ||
from feeds.spiders import FeedsSpider | ||
|
||
|
||
class DelinskiAtSpider(FeedsSpider): | ||
name = "delinski.at" | ||
|
||
feed_title = "Delinski" | ||
feed_link = "https://{}".format(name) | ||
feed_logo = "https://{}/favicon.ico".format(name) | ||
|
||
def start_requests(self): | ||
yield scrapy.Request( | ||
"https://www.delinski.at/wien/restaurants", | ||
# The restaurants page is not cached and takes a few seconds to load. | ||
# Don't query more than once a day. | ||
meta={"cache_expires": timedelta(days=1)}, | ||
) | ||
|
||
def parse(self, response): | ||
m = re.search("window.DELINSKI, {listViewEntities: (.*)}", response.text) | ||
restaurants = sorted( | ||
json.loads(m.group(1))["restaurants"]["entities"].values(), | ||
key=lambda r: int(r["created"]), | ||
reverse=True, | ||
) | ||
for restaurant in restaurants[:20]: | ||
il = FeedEntryItemLoader(timezone="Europe/Vienna", base_url=response.url) | ||
url = response.urljoin(restaurant["url"]) | ||
il.add_value("link", url) | ||
il.add_value("title", restaurant["name"]) | ||
content = """ | ||
<img src="{image}"> | ||
<ul> | ||
<li>{address}</li> | ||
<li>{price_range_human}</li> | ||
<li>{cuisine_text}</li> | ||
</ul> | ||
""" | ||
il.add_value("content_html", content.format(**restaurant)) | ||
il.add_value("updated", datetime.fromtimestamp(int(restaurant["created"]))) | ||
yield scrapy.Request(url, self._parse_restaurant, meta={"il": il}) | ||
|
||
def _parse_restaurant(self, response): | ||
il = FeedEntryItemLoader( | ||
response=response, | ||
base_url=response.url, | ||
parent=response.meta["il"], | ||
remove_elems=[".external"], | ||
) | ||
il.add_css("content_html", ".content .right p") | ||
il.add_css("content_html", ".restaurant-link") | ||
il.add_css("category", ".tags a ::text") | ||
yield il.load_item() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters