Created
April 30, 2010 04:13
-
-
Save k-saka/384730 to your computer and use it in GitHub Desktop.
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 | |
import sqlite3 | |
import time | |
username = '' | |
password = '' | |
def get_api(): | |
auth = tweepy.BasicAuthHandler(username,password) | |
api = tweepy.API(auth) | |
return api | |
def get_user_timeline(id = None): | |
api = get_api() | |
statuses = None | |
try: | |
statuses = api.user_timeline(count=200,max_id = id) | |
except tweepy.error.TweepError as er: | |
print er.args | |
print er | |
return statuses | |
def connect_db(): | |
conn = sqlite3.connect('tl.db') | |
return conn | |
def insert_db(id,text): | |
conn = connect_db() | |
cur = conn.cursor() | |
#sql = u'insert into status values(?,?);' | |
sql = u'insert into status(id,text) values(?,?);' | |
conn.execute(sql, (id,text)) | |
conn.commit() | |
def main(): | |
status_id = None | |
i = 0 | |
while i < 31: | |
statuses = get_user_timeline(id = status_id) | |
if statuses != None: | |
for status in statuses: | |
print status.text,status.id | |
insert_db(status.id,status.text) | |
status_id = status.id-1 | |
print '‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾', i | |
i+=1 | |
time.sleep(5) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment