Twitter graphing memo with Python

Background / execution environment

See this [article] by Anchibe-san (http://antibayesian.hateblo.jp/entry/20110828/1314491180), ・ Python3 (3.5.1) ・ Windows 10 (64bits) -Install python with anaconda I tried to do the same in my environment.

See additional: ・ Http://www.slideshare.net/pika_shi/pythontwittertwitter -Htp: // d. Hatena. Right. jp / Hangyo 22/20120430/1335786712 ・ Http://blog.kzfmix.com/entry/1206780815 Thanks to everyone who publishes useful information online.

Python-twitter version

For the time being, when I went to the point of drawing a graph on 2016/06/11, the version I am using is 3.1. Since I am stuck with API restrictions, I changed the source of 3.1 and used it.

Source (part)

For the basics, please refer to Anchibe's page. Below are some minor changes.

api = twitter.Api(consumer_key='***',  #your_consumer_key,
        consumer_secret='***',  #your_consumer_secret,
        access_token_key='***',  #your_access_token_key,
        access_token_secret='***',  #your_access_token_secret,
	    input_encoding = "utf-8",
        sleep_on_rate_limit=True)

First, install Python-twitter.

Since I installed it with anaconda, I wanted to do it with conda, but I could not install the latest version 3.0rc1 of python-twitter as of 2016/05 (it seems that changes have been made to support Python v3), so Use pip. pip install python-twitter==3.0rc1 ⇒ As of May 28, 2016, the latest version is 3.1, so It will be pip install python-twitter == 3.1.

conda list A list of packages installed in is displayed, so check that python-twitter is installed.

When the version of python-twitter was 3.0rc1, an error occurred when there was input_encording ='utf-8' in twitter.Api (), but it was resolved when the version became 3.1.

Python-twitter feature overview (partial)

GetFriends seems to be an operation that collects information on everyone, not just 100 people. If you don't need a lot of information to check the operation of the source, you can set the upper limit with'total_count ='in twitter.Api ().

Also, there is a setting such as timeout = (default 60 seconds), so it may be better to review the setting if the line is unstable. * I'm not sure.

Program execution

As a result, graph drawing is completed. Next, derive meaningful results from the graph. This is not yet.

twitter.error.TwitterError: [{'message': 'Rate limit exceeded', 'code': 88}] Came out. As a response, even if I tried to set sleep_on_rate_limit = True, it was displayed in python-twitter == 3.0rc1 that it was an error in __init__, but as of May 28, 2016, the latest, 3.1 shows an error It is no longer done. Therefore solved.

In the calculation of the number of seconds to sleep in time.sleep in _RequestUrl () of Python-twitter, it is truncated after the decimal point by int (), so I added the surplus number here and checked the operation, but only here It doesn't seem to matter much because you can't avoid getting stuck in API call restrictions by changing.

The final change to avoid API restrictions was to change some of the python-twitter source. Changed the process that sleeps when the API remaining number is just 0 to sleep when the API remaining number is 2 or less.

So far, I can draw a graph, but I can't find any meaning in the result. There are various possible reasons for this, such as whether you are following too many people in various fields, or whether you need to devise an algorithm for drawing network graphs, but it is unknown at this time. We will continue to confirm.

How to avoid API limits obtained from execution results (overview)

-Edit python-twitter api.py. -(This may not work) time.sleep (int (...) + seconds) -Only when API remaining == 0, change the condition of the if statement to sleep, for example, to sleep at 2 or less.

https://github.com/bear/python-twitter/issues/350

Recommended Posts

Twitter graphing memo with Python
[Memo] Tweet on twitter with python
Get Twitter timeline with python
Use Twitter API with Python
Search twitter tweets with python
python memo
Python memo
python memo
Python memo
Python memo
Python memo
A python graphing manual with Matplotlib.
python memo --Specify options with getopt
Input / output with Python (Python learning memo ⑤)
Post multiple Twitter images with python
Easily post to twitter with Python 3
"Scraping & machine learning with Python" Learning memo
Collecting information from Twitter with Python (Twitter API)
[Python] Memo dictionary
FizzBuzz with Python3
Scraping with Python
Statistical basics and Python, graphing, etc. (memo)
Convert memo at once with Python 2to3
python beginner memo (9.2-10)
Statistics with python
Memo to ask for KPI with python
twitter on python3
Scraping with Python
Python with Go
python beginner memo (9.1)
"System trade starting with Python3" reading memo
Tweet from python with Twitter Developer + Tweepy
Twilio with Python
A memo with Python2.7 and Python3 on CentOS
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
★ Memo ★ Python Iroha
python starts with ()
with syntax (Python)
[Python] EDA memo
Python 3 operator memo
Bingo with python
Zundokokiyoshi with python
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
Let's make a Twitter Bot with Python!
Python beginner memo (2)
Excel with Python
[Python] Numpy memo
Microcomputer with Python
Cast with python
Collecting information from Twitter with Python (Environment construction)
[Personal memo] julia --Using Python library with julia using PyCall
Make a Twitter trend bot with heroku + Python
I made a Twitter fujoshi blocker with Python ①
Post youtube soaring title to twitter with python3
A memo when creating a python environment with miniconda
Steps to create a Twitter bot with python