Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created January 20, 2010 17:24
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 mizchi/282021 to your computer and use it in GitHub Desktop.
Save mizchi/282021 to your computer and use it in GitHub Desktop.
#/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