将来自多个源的数据聚合到合并和筛选的Atom提要中。
resyndicator的Python项目详细描述
最好在https://resyndicator.readthedocs.io/上查看此文档。
目的
resyndicator是一个python 3框架,用于聚合来自 源进入原子馈送。如果你有几百个数据的列表 源(如feed、sitemaps和twitter用户)希望共享 在各种设备(计算机、电话等)之间输入 同事,甚至你网站的访问者,那就是 重新联合是为了。
- 它可以从feed、站点地图、社交媒体和您实现的任何其他源获取数据。
- 它允许像sqlalchemy允许过滤一样复杂的查询。 你的总饲料。
- 它允许您轻松地对获取程序进行子类化,因此您可以为 像adobe的amf一样模糊的端点。
- 它将所有条目保存在postgres中,因此您有一个备份。
我一直在为EA Foundation、.impact、Saram、Derpy News和Ferret Go使用resyndicator,logitech的一个营销部门也曾表示有兴趣。
设置
我已经创建了一个sample implementation的resyndicator框架来简化安装过程。你可以用叉子叉它,然后根据你的目的调整它。(我一直遵循将我的实现称为“soandsofeeder”的惯例——一个以“feeder”结尾的单词,中间没有连字符或空格。)Resyndicator is hosted on PyPI,因此您可以通过pip安装它。
- 一个重要的文件是samplefeeder/settings.py带有一些常规设置。有关默认值,请参见resyndicator/settings.py。
- 另一个是samplefeeder/resources.py。
设置
在settings.py中,您尤其需要使用以下内容更改数据库凭据 DATABASE = 'postgresql://foo:bar@localhost/samplefeeder'(您可以 需要创建数据库并授予用户访问权限)。除了博士后,我什么都没试过。
为了 更多选项,请参见resyndicator/settings.py。
注意:您可以像这样创建数据库:
create role samplefeeder with password 'samplefeeder' login; create database samplefeeder with owner samplefeeder;
我的系统用utf-8编码自动创建它,但是一些debian系统打包了 默认情况下使用一些奇怪编码的Postgres。在这种情况下,请确保从正确的模板继承。
postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges --------------------------+----------------+-----------+-------------+-------------+------------------------------- postgres | postgres | UTF8 | en_DK.UTF-8 | en_DK.UTF-8 | samplefeeder | samplefeeder | UTF8 | en_DK.UTF-8 | en_DK.UTF-8 |
资源
在resources.py中,列出提要和(同名)重新同步器 例如:
from datetime import timedelta from sqlalchemy.sql import or_ from resyndicator import settings from resyndicator.models import Entry from resyndicator.fetchers import ( FeedFetcher, SitemapIndexFetcher, SitemapFetcher, TwitterFetcher, ContentFetcher) from resyndicator.resyndicators import Resyndicator from . import settings CONTENT_FETCHERS = [ ContentFetcher(past=settings.PAST, timeout=10) ] RESYNDICATORS = [ Resyndicator( title='Effective Altruism', past=PAST, query=or_( Entry.source_link.in_([ 'http://feeds.feedburner.com/TheGivewellBlog', 'http://www.openphilanthropy.org/sitemap.xml', ]) ) ) ] FETCHERS = [ FeedFetcher('http://feeds.feedburner.com/TheGivewellBlog', interval=10*60), SitemapFetcher('http://www.openphilanthropy.org/sitemap.xml', defaults={'title': 'Open Phil Sitemap', 'author': 'Open Philanthropy Project'}, interval=30*60), ] STREAMS = [ TwitterFetcher( oauth_token=settings.OAUTH_TOKEN, oauth_secret=settings.OAUTH_SECRET, interval=5*60), ]
SampleFeeder包含一个工作示例^{TT3}$,您可以对其进行调整。它错过了 示例TwitterFetcher,这样它就不会公开OAuth机密。
对于每个resyndicator,您定义一个查询和一个标题,它将 确定它的id,从而确定它的身份。如果你换了头衔 创建一个新的、不同的提要。查询确定提要的条目和 指定为SQLAlchemy where statements。
要构建samplefeeder fork,请运行make。
运行它
您可以检查samplefeeder中包含的supervisord.conf以获取样本调用。
注意:resyndicator需要python 3(我还没有用python3.4之前的版本测试过它),而supervisor只在版本4.0上支持python3,因此您需要两个不同的python来以这种方式运行它。(但是通过supervisor运行python 3应用程序没有问题。)
[program:fetcher] command = bin/resyndicator -s samplefeeder.settings fetchers ... [program:content] command = bin/resyndicator -s samplefeeder.settings content ...
您可以使用bin/resyndicator -s samplefeeder.settings fetchers --test-mode来指示重新同步器忽略间隔并立即获取所有提要,这样您就不必等待它们是否有任何故障。
提供饲料
提要将写入webroot/子目录中的文件。把你的nginx或清漆指向这个 提供源的目录。nginx示例:
server { listen 80; listen [::]:80; server_name feeds.example.com; charset utf-8; keepalive_timeout 5; root /opt/samplefeeder/webroot/; access_log /var/log/nginx/feeds.access.log main; }
测试
您可以使用pytest运行测试:
- make安装带有重新同步器和依赖项的virtualenv
- bin/pip install pytest
- bin/py.test resyndicator