Created
January 20, 2010 17:24
-
-
Save mizchi/282021 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
#/usr/bin/python | |
# -*- encoding:utf8 -*- | |
import sqlite3 , twitter | |
from time import strftime ,sleep | |
""" | |
Twitterのログをとる | |
要:Python-Twitter | |
$sudo easy_install twitter などする | |
""" | |
user="user" | |
password="pass" | |
api = twitter.Api(user, password) | |
#db | |
db=sqlite3.connect('tw.db') | |
try: | |
db.execute('create table timeline(screen_name,text,id,time') | |
except: | |
pass | |
#再起動時に重複を防ぐ | |
last_id= db.cursor().execute("select * from timeline order by id desc").fetchone()[2] | |
print "Logging Start" | |
while 1: | |
try: | |
tl = api.GetFriendsTimeline(count=150,since_id=last_id) | |
last_id=tl[0].id | |
for i in tl: | |
time=strftime("%Y-%m-%d %H:%M") | |
print "%s:%s /%s" %(i.user.screen_name ,i.text , i.created_at) | |
db.execute('insert into timeline(screen_name,text,id,time) values (?,?,?,?)', | |
( i.user.screen_name ,i.text ,i.id, time)) | |
db.commit() | |
sleep(60) | |
except: | |
sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment