twitter-apiによる自分アカウントへきた返信の取得


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #Twitterからあるユーザの直近の質問をとってくる
  2. import datetime
  3. import locale
  4. from datetime import timedelta
  5. def GetresponseTwitter():
  6. #url作成
  7. d=datetime.datetime.today()
  8. dt1 = timedelta(seconds=60*60*9)#twitterの時刻は9時間前
  9. dt2 = timedelta(seconds=const_time)
  10. new_d = d-dt1-dt2#10分前の時刻を取得
  11. since=sinceParm(new_d)#sinceパラメータの作成
  12. url = 'http://twitter.com/statuses/replies.xml?since=%s'%since
  13.  
  14. base64string =b64encode("%s:%s" % (username, password))#username,passwordは自分で定義すること
  15. headers = {"Authorization": "Basic %s" % base64string}
  16. xml_result=urlfetch.fetch(url, payload='', method=urlfetch.POST, headers=headers).content
  17.  
  18. result=[]
  19. for soup in BeautifulSoup(xml_result)('status'):
  20. try:
  21. print >>sys.stderr,'text=%s'%htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
  22. text=htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
  23. except:
  24. print >>sys.stderr,'text=%s'%htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
  25. text=htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1])
  26. user=htmlentity2unicode(soup('screen_name')[0](text = True)[0])
  27. result.append([text,user])
  28. return result

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.