Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/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)
Add Comment
Please, Sign In to add comment