-
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 #220 from PyFeeds/dev/nblock
Spider for tinyletter.com and smaller fixes
- Loading branch information
Showing
20 changed files
with
102 additions
and
7 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
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,25 @@ | ||
.. _spider_tinyletter.com: | ||
|
||
tinyletter.com | ||
-------------- | ||
Latest articles from `tinyletter <tinyletter.com>`_ users. | ||
|
||
Configuration | ||
~~~~~~~~~~~~~ | ||
Add ``tinyletter.com`` to the list of spiders: | ||
|
||
.. code-block:: ini | ||
# List of spiders to run by default, one per line. | ||
spiders = | ||
tinyletter.com | ||
At least one account is required. The account name is visible on the | ||
subscription page, e.g. for http://tinyletter.com/dabeaz, the account name is | ||
``dabeaz``. | ||
|
||
.. code-block:: ini | ||
[tinyletter.com] | ||
accounts = | ||
dabeaz |
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,64 @@ | ||
import scrapy | ||
|
||
from feeds.loaders import FeedEntryItemLoader | ||
from feeds.spiders import FeedsSpider | ||
from feeds.utils import generate_feed_header | ||
|
||
|
||
class TinyletterComSpider(FeedsSpider): | ||
name = "tinyletter.com" | ||
allowed_domains = ["tinyletter.com"] | ||
|
||
_base_url = f"https://{name}" | ||
_titles = {} | ||
_subtitles = {} | ||
_links = {} | ||
|
||
def start_requests(self): | ||
self._accounts = self.settings.get("FEEDS_SPIDER_TINYLETTER_COM_ACCOUNTS", []) | ||
if self._accounts: | ||
self._accounts = set(self._accounts.split()) | ||
else: | ||
self.logger.error("No accounts given!") | ||
return | ||
|
||
for account in self._accounts: | ||
yield scrapy.Request( | ||
f"{self._base_url}/{account}/archive?recs=1000", | ||
meta={"dont_cache": True, "account": account}, | ||
) | ||
|
||
def feed_headers(self): | ||
for account in self._accounts: | ||
yield generate_feed_header( | ||
title=self._titles.get(account), | ||
subtitle=self._subtitles.get(account), | ||
link=self._links.get(account), | ||
icon=f"{self._base_url}/site/favicon.ico", | ||
logo=f"{self._base_url}/site/assets/images/brand-assets/TL_logo.svg", | ||
path=account, | ||
) | ||
|
||
def parse(self, response): | ||
account = response.meta["account"] | ||
self._titles[account] = response.css("title::text").get() | ||
self._subtitles[account] = response.css( | ||
"meta[property='og:description']::attr('content')" | ||
).get() | ||
self._links[account] = f"{self._base_url}/{account}/archive" | ||
|
||
for u in response.css("ul.message-list a.message-link::attr('href')").getall(): | ||
yield scrapy.Request( | ||
u, self.parse_letter, meta={"account": account}, | ||
) | ||
|
||
def parse_letter(self, response): | ||
account = response.meta["account"] | ||
il = FeedEntryItemLoader(response=response, base_url=self._links.get(account)) | ||
il.add_value("path", account) | ||
il.add_value("link", response.url) | ||
il.add_css("title", "title::text") | ||
il.add_css("author_name", "div#message-heading div.by-line a::text") | ||
il.add_css("updated", "div#message-heading div.date::text") | ||
il.add_css("content_html", "div.message-body") | ||
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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