Collecting tweets with Python

Collect tweets with python. It is mainly used when you want to get information from XX bots when learning machines. (In the case of I) The contents of 〇〇bot etc. are very biased, For example, it can be said that there are many tweets about tsundere in tsundere bots. This is a collection of tsundere lines for this account, all of which can be recognized as tsundere lines, and to put it simply, a model of "spam or not", that is, tsundere classified as tsundere or not. Can be used for.

The introduction has been lengthened, but there are only a few lines of code to retrieve tweets. Library uses Tweepy, so if you don't have it installed

command


pip install tweepy
or
sudo easy_install tweepy

You can install it with.

You need to get CK, CS, AK, AT to actually work. Please create a new app from the URL below and get a Token https://apps.twitter.com/ get_timeline () for each (Id) of the account you want to get, Number of tweets to get (cout) Apply.

get_timeline


#coding: utf-8
import tweepy

CK = ""
CS = ""
AK = ""
AT = ""

def get_twitter_api(CK, CS, AK, AT):
	auth = tweepy.OAuthHandler(CK, CS)
	auth.set_access_token(AK, AT)
	api = tweepy.API(auth)
	return api

def get_timeline(id, count=100):
	API = get_twitter_api(CK, CS, AK, AT)
	i = API.user_timeline(id=id, count=count)
	with open("", "w") as f:
		for k in i:
			encode = k.text+'\n'
			f.write(encode.encode('utf-8'))

if __name__ == '__main__':
	get_timeline(id="", count=100)

Recommended Posts

Collecting tweets with Python
Posting tweets with python
Search twitter tweets with python
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Collecting information from Twitter with Python (Twitter API)
Exclude tweets containing URLs with tweepy [Python]
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Collecting information from Twitter with Python (Environment construction)
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
1.1 Getting Started with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Drive WebDriver with python
Use mecab with Python3
[Python] Redirect with CGIHTTPServer
Voice analysis with python
Think yaml with python
Operate Kinesis with Python
Getting Started with Python
Use DynamoDB with Python
Zundko getter with python
Handle Excel with python
Ohm's Law with Python
Primality test with python
Run Blender with python