Python 收集Twitter时间序列数据
CODE:
#!/usr/bin/python
# -*- coding: utf-8 -*- '''
Created on 2014-7-18
@author: guaguastd
@name: collect_time_series.py
''' if __name__ == '__main__': # import json
import json # import partial
from functools import partial # import trend
from trend import twitter_trends # import time_series
from time_series import get_time_series_data # import login, see http://blog.csdn.net/guaguastd/article/details/31706155
from login import twitter_login # get the twitter access api
twitter_api = twitter_login() # sample usage
WORLD_WOE_ID = 1
pp = partial(json.dumps, indent=1)
twitter_world_trends = partial(twitter_trends, twitter_api, WORLD_WOE_ID) # collect time series
get_time_series_data(twitter_world_trends, 'time-series', 'twitter_world_trends')
RESULT:
data:
[{u'locations': [{u'woeid': 1, u'name': u'Worldwide'}], u'created_at': u'2014-07-17T22:46:34Z', u'_id': ObjectId('53c852dcae6f221648bfdde9'), u'trends': [{u'url': u'http://twitter.com/search?q=%23MH17', u'query': u'%23MH17', u'name': u'#MH17', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%23GazzeSiyonizmeMezarOlacak', u'query': u'%23GazzeSiyonizmeMezarOlacak', u'name': u'#GazzeSiyonizmeMezarOlacak', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23PrayForMH17', u'query': u'%23PrayForMH17', u'name': u'#PrayForMH17', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%23LouisWeLoveYou', u'query': u'%23LouisWeLoveYou', u'name': u'#LouisWeLoveYou', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%23SpamIsraelinTurkey', u'query': u'%23SpamIsraelinTurkey', u'name': u'#SpamIsraelinTurkey', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22MuhsinBa%C5%9Fkan+Erdo%C4%9Fan%C4%B1Desteklerdi%22', u'query': u'%22MuhsinBa%C5%9Fkan+Erdo%C4%9Fan%C4%B1Desteklerdi%22', u'name': u'MuhsinBa\u015fkan Erdo\u011fan\u0131Desteklerdi', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%22SoyunKurusun+Katilisrail%22', u'query': u'%22SoyunKurusun+Katilisrail%22', u'name': u'SoyunKurusun Katilisrail', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22IsraelIsSlaughtering+TheworldIsWatching%22', u'query': u'%22IsraelIsSlaughtering+TheworldIsWatching%22', u'name': u'IsraelIsSlaughtering TheworldIsWatching', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%22Elaine+Stritch%22', u'query': u'%22Elaine+Stritch%22', u'name': u'Elaine Stritch', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%22%C5%9EimdiDuaVakti+GazzeYan%C4%B1yor%22', u'query': u'%22%C5%9EimdiDuaVakti+GazzeYan%C4%B1yor%22', u'name': u'\u015eimdiDuaVakti GazzeYan\u0131yor', u'promoted_content': None}], u'as_of': u'2014-07-17T22:49:01Z'}] Write 1 trends
Zzz...
data:
[{u'locations': [{u'woeid': 1, u'name': u'Worldwide'}], u'created_at': u'2014-07-17T22:46:34Z', u'_id': ObjectId('53c8531eae6f221648bfddea'), u'trends': [{u'url': u'http://twitter.com/search?q=%23MH17', u'query': u'%23MH17', u'name': u'#MH17', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%23GazzeSiyonizmeMezarOlacak', u'query': u'%23GazzeSiyonizmeMezarOlacak', u'name': u'#GazzeSiyonizmeMezarOlacak', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23PrayForMH17', u'query': u'%23PrayForMH17', u'name': u'#PrayForMH17', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23LouisWeLoveYou', u'query': u'%23LouisWeLoveYou', u'name': u'#LouisWeLoveYou', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%23SpamIsraelinTurkey', u'query': u'%23SpamIsraelinTurkey', u'name': u'#SpamIsraelinTurkey', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22MuhsinBa%C5%9Fkan+Erdo%C4%9Fan%C4%B1Desteklerdi%22', u'query': u'%22MuhsinBa%C5%9Fkan+Erdo%C4%9Fan%C4%B1Desteklerdi%22', u'name': u'MuhsinBa\u015fkan Erdo\u011fan\u0131Desteklerdi', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22SoyunKurusun+Katilisrail%22', u'query': u'%22SoyunKurusun+Katilisrail%22', u'name': u'SoyunKurusun Katilisrail', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22IsraelIsSlaughtering+TheworldIsWatching%22', u'query': u'%22IsraelIsSlaughtering+TheworldIsWatching%22', u'name': u'IsraelIsSlaughtering TheworldIsWatching', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Elaine+Stritch%22', u'query': u'%22Elaine+Stritch%22', u'name': u'Elaine Stritch', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%22%C5%9EimdiDuaVakti+GazzeYan%C4%B1yor%22', u'query': u'%22%C5%9EimdiDuaVakti+GazzeYan%C4%B1yor%22', u'name': u'\u015eimdiDuaVakti GazzeYan\u0131yor', u'promoted_content': None}], u'as_of': u'2014-07-17T22:50:08Z'}]
Write 1 trends
Zzz... data:
[{u'locations': [{u'woeid': 1, u'name': u'Worldwide'}], u'created_at': u'2014-07-17T22:46:34Z', u'_id': ObjectId('53c85361ae6f221648bfddeb'), u'trends': [{u'url': u'http://twitter.com/search?q=%23MH17', u'query': u'%23MH17', u'name': u'#MH17', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23GazzeSiyonizmeMezarOlacak', u'query': u'%23GazzeSiyonizmeMezarOlacak', u'name': u'#GazzeSiyonizmeMezarOlacak', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23PrayForMH17', u'query': u'%23PrayForMH17', u'name': u'#PrayForMH17', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23LouisWeLoveYou', u'query': u'%23LouisWeLoveYou', u'name': u'#LouisWeLoveYou', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SpamIsraelinTurkey', u'query': u'%23SpamIsraelinTurkey', u'name': u'#SpamIsraelinTurkey', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22MuhsinBa%C5%9Fkan+Erdo%C4%9Fan%C4%B1Desteklerdi%22', u'query': u'%22MuhsinBa%C5%9Fkan+Erdo%C4%9Fan%C4%B1Desteklerdi%22', u'name': u'MuhsinBa\u015fkan Erdo\u011fan\u0131Desteklerdi', u'promoted_content': None}, {u'url': u'http://twitter.com/search? q=%22SoyunKurusun+Katilisrail%22', u'query': u'%22SoyunKurusun+Katilisrail%22', u'name': u'SoyunKurusun Katilisrail', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22IsraelIsSlaughtering+TheworldIsWatching%22', u'query': u'%22IsraelIsSlaughtering+TheworldIsWatching%22', u'name': u'IsraelIsSlaughtering TheworldIsWatching', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Elaine+Stritch%22', u'query': u'%22Elaine+Stritch%22', u'name': u'Elaine Stritch', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22%C5%9EimdiDuaVakti+GazzeYan%C4%B1yor%22', u'query': u'%22%C5%9EimdiDuaVakti+GazzeYan%C4%B1yor%22', u'name': u'\u015eimdiDuaVakti GazzeYan\u0131yor', u'promoted_content': None}], u'as_of': u'2014-07-17T22:51:15Z'}] Write 1 trends
Zzz...
Python 收集Twitter时间序列数据的更多相关文章
- python时间序列数据的对齐和数据库的分批查询
欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 0. 前言 在机器学习里,我们对时间序列数据做预处理的时候,经常会碰到一个问题:有多个时间序列存在多个表里,每个表的的时间轴不完全相同,要如 ...
- Python调用Prometheus监控数据并计算
Prometheus是什么 Prometheus是一套开源监控系统和告警为一体,由go语言(golang)开发,是监控+报警+时间序列数 据库的组合.适合监控docker容器.因为kubernetes ...
- PIE SDK打开长时间序列数据
1. 功能简介 时间序列数据(time series data)是在不同时间上收集到的数据,这类数据是按时间顺序收集到的,用于所描述现象随时间变化的情况.当前随着遥感卫星技术日新月异的发展,遥感卫星的 ...
- Python数据分析 之时间序列基础
1. 时间序列基础 import numpy as np import pandas as pd np.random.seed(12345) import matplotlib.pyplot as p ...
- 利用python实现平稳时间序列的建模方式
一.平稳序列建模步骤 假如某个观察值序列通过序列预处理可以判定为平稳非白噪声序列,就可以利用ARMA模型对该序列进行建模.建模的基本步骤如下: (1)求出该观察值序列的样本自相关系数(ACF)和样本偏 ...
- 时间序列数据的定义,读取与指数平滑(Java)
应上头的要求,需要实现以下指数平滑进行资源调度负载的预测,那就是用我最喜欢的Java做一下吧. 引用<计量经济学导论>的一句话:时间序列数据区别于横截面数据的一个明显特点是,时间序列数据集 ...
- Python数学建模-02.数据导入
数据导入是所有数模编程的第一步,比你想象的更重要. 先要学会一种未必最佳,但是通用.安全.简单.好学的方法. 『Python 数学建模 @ Youcans』带你从数模小白成为国赛达人. 1. 数据导入 ...
- 通过Python收集MySQL MHA 部署及运行状态信息的功能实现
一. 背景介绍 当集团的MySQL数据库实例数达到2000+.MHA集群规模数百个时,对MHA的及时.高效管理是DBA必须面对的一个挑战.MHA 集群 节点信息 和 运行状态 是管理的基础.本篇幅主要 ...
- Python收集这些视频只是单纯的想做做壁纸,大家不要误会
首先澄清一下,我用Python收集这些视频,绝不是想做别的什么,真的只是用来做动态壁纸,大家不要误会!我不是那样的人~ 这样的不过份吧 (这个动图看不看的到就看有没有缘分了 ) 阅读本文你需要准备 1 ...
随机推荐
- U盘安装Ubuntu kylin版
初试U盘安装Ubuntu14.04 kylin版 等待Ubuntu14.04 kylin版出来后,一直想要尝试在物理机进行安装体验,恰巧碰到五一假期,因为咱是穷人,没钱出去玩,所以就有了时间实地进行 ...
- 为什么必须是final的呢?
一个谜团 如果你用过类似guava这种“伪函数式编程”风格的library的话,那下面这种风格的代码对你来说应该不陌生: 1 2 3 4 5 6 7 8 9 public void tryUsingG ...
- Servlet过滤器——创建过滤器
1.概述 介绍如何创建一个过滤器,并使用过滤器在打开页面的同时输出信息,此功能是由过滤器处理完成的. 2.技术要点 Serlvet过滤器实现了Filter接口,在Filter接口中定义了以下几个方法: ...
- SpringMVC从Control中响应json数据
在页面上异步获取Controller中响应的json数据. <%@ page language="java" contentType="text/html; cha ...
- JAVA之成员变量初始化
java中成员变量的初始化,如果是普通成员变量可以赋初值,如果没赋初值,则系统会自动赋初值.而对于局部变量必须手动赋初值. package MyText2; public class MyText1 ...
- Spark大型项目实战:电商用户行为分析大数据平台
本项目主要讲解了一套应用于互联网电商企业中,使用Java.Spark等技术开发的大数据统计分析平台,对电商网站的各种用户行为(访问行为.页面跳转行为.购物行为.广告点击行为等)进行复杂的分析.用统计分 ...
- gcc中__attribute__ ((constructor(101)))做成.a库成功链接
1.cpp:------------------------------------------------ #include int test() __attribute__ ((construct ...
- 【从零学习openCV】opecv操作像素
1. 存取像素值 在opencv中能够直接对cv::Mat类型的图像调用at函数读取或赋值某个像素,我们用个简单的案例来说明: //在一张图像上增加椒盐噪声,image为输入图像.n为噪点个数 voi ...
- Swift - 本地数据的保存与加载(使用NSCoder将对象保存到.plist文件)
下面通过一个例子将联系人数据保存到沙盒的“documents”目录中.(联系人是一个数组集合,内部为自定义对象). 功能如下: 1,点击“保存”将联系人存入userList.plist文件中 2,点击 ...
- Maven项目下 java.lang.ClassNotFoundException 常规解决的方法
网上非常多要改动.class .project的比較麻烦有时候还不一定管用.以下的方法适合于项目用已经引用了jar.可是执行时却ClassNotFound,请用例如以下方法试试: 严重: Error ...