Guest User

Untitled

a guest
Apr 7th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #/usr/bin/python
  2. # -*- encoding:utf8 -*-
  3. import sqlite3 , twitter
  4. from time import strftime ,sleep
  5.  
  6. """
  7. Twitterのログをとる
  8.  
  9. 要:Python-Twitter
  10. $sudo easy_install twitter などする
  11. """
  12.  
  13. user="user"
  14. password="pass"
  15.  
  16. api = twitter.Api(user, password)
  17.  
  18. #db
  19. db=sqlite3.connect('tw.db')
  20. try:
  21. db.execute('create table timeline(screen_name,text,id,time')
  22. except:
  23. pass
  24.  
  25. #再起動時に重複を防ぐ
  26. last_id= db.cursor().execute("select * from timeline order by id desc").fetchone()[2]
  27. print "Logging Start"
  28. while 1:
  29. try:
  30. tl = api.GetFriendsTimeline(count=150,since_id=last_id)
  31. last_id=tl[0].id
  32. for i in tl:
  33. time=strftime("%Y-%m-%d %H:%M")
  34. print "%s:%s /%s" %(i.user.screen_name ,i.text , i.created_at)
  35. db.execute('insert into timeline(screen_name,text,id,time) values (?,?,?,?)',
  36. ( i.user.screen_name ,i.text ,i.id, time))
  37. db.commit()
  38. sleep(60)
  39. except:
  40. sleep(60)
Add Comment
Please, Sign In to add comment