Last active
June 29, 2017 17:41
-
-
Save naari3/64cb1083c6c5b4c556bd96333c082f15 to your computer and use it in GitHub Desktop.
idにscreen_nameを指定したらsqlite3でいろいろ保存されていく
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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