自动收集Twitter流数据
twistream的Python项目详细描述
Twistream:Twitter流API数据收集
Twistream帮助您从Twitter流API自动收集和存储数据。在
安装
最新稳定版本:
pip install twistream
来源:
^{pr2}$设置
Twitter凭据
您需要您的twitter凭据才能使用twitter API。为此, 创建应用程序here。创建后,保存要配置的凭据 扭流
创建配置文件
您可以使用命令twistream init
来帮助您创建格式正确的配置文件
为了你的收藏。在
创建后,您将有一个文件,该文件将如下所示:
~> cat ~/.twistream/twistream.yml
twitter:
consumer_key: your_consumer_key
consumer_secret: your_consumer_secret
access_token_key: your_access_token_key
access_token_secret: your_access_token_secret
backend: backend_name
backend_params:
username: db_username
password: db_password
使用
记住,--help
始终是一个可用的选项
一旦创建了配置文件,就开始收集tweets!在
twistream collect --tracks tracks,to,follow config.yaml
请参阅twitter documentation以了解哪些轨迹,简而言之:
A comma-separated list of phrases which will be used to determine what Tweets will be delivered on the stream. A phrase may be one or more terms separated by spaces, and a phrase will match if all of the terms in the phrase are present in the Tweet, regardless of order and ignoring case. By this model, you can think of commas as logical ORs, while spaces are equivalent to logical ANDs (e.g. ‘the twitter’ is the AND twitter, and ‘the,twitter’ is the OR twitter).
如果您想要跟随hashtags,请不要忘记包含#
字符。在
支持的后端
从版本0.1.3开始,twistream支持两个后端。关系数据库(SQLite)和非sql数据库(MongoDB)。在
请注意,SQLite后端只保存几个tweet字段,而MongoDB后端将保存整个blob。 它是信息和存储空间之间的权衡。在
后端参数格式
SQLite
backend: sqlite
backend_params:
db_path: /path/to/your/db
MongoDB
backend: mongodb
backend_params:
db_string: database_connection_string
(请参阅数据库连接字符串文档)
- 项目
标签: