Convert Tweepy Status object to JSON

I was in trouble when I wanted to export with json, but I could not find it even if I looked at the document or googled, so a memo

After all, you can do it with t._json ( t is Tweepy's Status object).

get_as_json.py


import sys
import tweepy
import json

consumer_key = sys.argv[1]
consumer_secret = sys.argv[2]
access_token = sys.argv[3]
access_token_secret = sys.argv[4]
screen_name = sys.argv[5]

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
client = tweepy.API(auth)

tweets = client.user_timeline(screen_name=screen_name)
for t in tweets:
	t_json = t._json 										#Here
	print json.dumps(t_json)

use

$ python get_as_json.py CONSUMER_KEY CONSUMER_SECRET ACCESS_TOKEN ACCESS_TOKEN_SECRET user_name

Recommended Posts

Convert Tweepy Status object to JSON
Convert json to excel
Parse JSON file to object
Convert / return class object to JSON format in Python
Convert (compress) formatted JSON string to 1-line JSON
Convert Excel data to JSON with python
Convert array (struct) to json with golang
Convert to HSV
How to generate a Python object from JSON
Convert json format data to txt (using yolo)
I convert AWS JSON data to CSV like this
Convert a slice object to a list of index numbers
Convert 202003 to 2020-03 with pandas
Convert kanji to kana
How to convert a class object to a dictionary with SQLAlchemy
Convert jupyter to py
Convert keras-yolo3 to onnx
How to read JSON
How to convert JSON file to CSV file with Python Pandas
Convert dict to array
How to convert Json file to CSV format or EXCEL format
Try writing JSON format data to object storage Cloudian/S3
Convert Pascal VOC format xml file to COCO format json file
Convert Select query obtained from Postgre with Go to JSON
Read json in C # and convert to dictionary type (forced)
Convert hexadecimal string to binary
[python] Convert date to string
Convert numpy int64 to python int
[Python] Convert list to Pandas [Pandas]
Convert HTML to text file
Convert Scratch project to Python
[Python] Convert Shift_JIS to UTF-8
Convert IP address to decimal
Convert SDF to CSV quickly
Convert genbank file to gff file
Convert python 3.x code to python 2.x
[Python] Convert CSV file uploaded to S3 to JSON file with AWS Lambda