Skip to content

Instantly share code, notes, and snippets.

@naari3
Last active June 29, 2017 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naari3/64cb1083c6c5b4c556bd96333c082f15 to your computer and use it in GitHub Desktop.
Save naari3/64cb1083c6c5b4c556bd96333c082f15 to your computer and use it in GitHub Desktop.
idにscreen_nameを指定したらsqlite3でいろいろ保存されていく
#coding: utf-8
import tweepy
CK = ""
CS = ""
AK = ""
AT = ""
from peewee import *
db = SqliteDatabase('tweet.db')
class Tweet(Model):
screen_name = TextField()
name = TextField()
text = TextField()
tweet_id = IntegerField()
tweet_created_at = DateTimeField()
class Meta:
database = db # This model uses the "people.db" database.
def tweet_parse(self, tw):
return self.create(
screen_name=tw.user.screen_name,
name=tw.user.name,
text=tw.text,
tweet_id=tw.id,
tweet_created_at=tw.created_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):
api = get_twitter_api(CK, CS, AK, AT)
for page in tweepy.Cursor(api.user_timeline, id=id).pages():
for tw in page:
t = Tweet().tweet_parse(tw)
if __name__ == '__main__':
db.create_tables([Tweet], True)
get_timeline(id="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment