/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#Twitterã‹ã‚‰ã‚るユーザã®ç›´è¿‘ã®è³ªå•ã‚’ã¨ã£ã¦ãã‚‹ import datetime import locale from datetime import timedelta def GetresponseTwitter(): #urlä½œæˆ d=datetime.datetime.today() dt1 = timedelta(seconds=60*60*9)#twitterã®æ™‚刻ã¯9æ™‚é–“å‰ dt2 = timedelta(seconds=const_time) new_d = d-dt1-dt2#10分å‰ã®æ™‚刻をå–å¾— since=sinceParm(new_d)#sinceパラメータã®ä½œæˆ url = 'http://twitter.com/statuses/replies.xml?since=%s'%since base64string =b64encode("%s:%s" % (username, password))#username,passwordã¯è‡ªåˆ†ã§å®šç¾©ã™ã‚‹ã“㨠headers = {"Authorization": "Basic %s" % base64string} xml_result=urlfetch.fetch(url, payload='', method=urlfetch.POST, headers=headers).content result=[] for soup in BeautifulSoup(xml_result)('status'): try: print >>sys.stderr,'text=%s'%htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1]) text=htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1]) except: print >>sys.stderr,'text=%s'%htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1]) text=htmlentity2unicode(soup('text')[0](text = True)[0].split(' ')[1]) user=htmlentity2unicode(soup('screen_name')[0](text = True)[0]) result.append([text,user]) return result