Return to Snippet

Revision: 12501
at March 17, 2009 15:37 by tamuratetsuya


Initial Code
#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

Initial URL

                                

Initial Description

                                

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

Initial Tags
google, python, django

Initial Language
Python