[[プログラム周り]]
-個人的にRSS取得プログラムが大流行。pythonでRSSを扱うプログラムを書いてみる。
[[feedparser:http://www.feedparser.org/]]を使うと良いようです。

-2ch_newsのRSSを取得する。
このサンプルでは、newsの中で、new速+とビジネス+をチョイスして記事の内容を取得している。最初上手く正規表現がマッチしなかったので、unicodeに変換してからマッチを行った。
 # -*- coding: cp932 -*-
 #parser_test
 import feedparser,urllib,string,re
 query='http://headline.2ch.net/bbynews/news.rss'
 lines=urllib.urlopen(query)
 d = feedparser.parse(lines.read())
 #print d.feed.title,d.feed.link
 for entry in d.entries:
     category=unicode(entry.category)
     if re.search(u'ビ\+',category) or re.search(u'速\+',category):
         print entry.title 
         print entry.modified
         str=entry.description
         str=str.replace(' ','')
         print str+'\n'
 #        print entry.title
 #    print 'title=:%s' % (entry.title)
 #    print 'category=:%s' % (entry.category)
 #    print 'date %s' % (entry.modified)
 #    print 'link %s' % (entry.link)
 #    print 'desq %s' % (entry.description)

-ヤフオクのRSSを取得する。

 #parser_test
 import feedparser,urllib
 query='http://search.auctions.yahoo.co.jp/search_rss?p=software+design&auccat=0&alocale=0jp&acc=jp'
 lines=urllib.urlopen(query)
 line=''
 for l in lines:
     line=line+l
 
 #print line
 
 d = feedparser.parse(line)
 cnt=0
 for entry in d.entries:
     cnt=cnt+1
     print 'count=:%d title=:%s description=:%s' % (cnt,entry.title,entry.description)

[[商社マンとYahoo!Auction RSS:http://teddy-g.cocolog-nifty.com/blog/2005/02/yahooauction_rs.html]]さん所を参考にすると、
 パラメータ"p"で検索ワードを指定するが、物によってはカテゴリが特定できずにRSSが返されない。
 パラメータ"sb"でモードを"desc"(Descriptionの略か)に指定するとタイトル一致検索になる。この場合、検索ワードはパラメータ"desc"で渡す。
 検索ワードの文字コードはEUC-JP。
 パラメータ"auccat"でオークションカテゴリを指定。省略すると"0"(=全カテゴリ)を指定したとみなされる。
 パラメータ"alocale"は詳細不明だが省略可能。デフォルトは"0"。
 パラメータ"acc"も詳細不明だが省略可能。デフォルトは"jp"(alocale、accとも国Or地域の指定?)。
 パラメータ"f"には"0x12"(アスキーコード表では装置制御2)の指定が必須。
とのこと。
RSSによって終了間近だが、誰も入札していないお得な商品のみを列挙するなどのサーチが出来るようになるかも知れない。

-ヤフオクのRSSを取得の続き
 # -*- coding: cp932 -*-
 #parser_test
 import feedparser,urllib,string,re,pykf,datetime
 def desc_conv_pptd(descriptoin=''):
     list=descriptoin.split(',')
     if len(list)==3:
         price,bid,expiration=list[-3],list[-2],list[-1]
     elif len(list)==4:
         price,bid,expiration=list[-4]+list[-3],list[-2],list[-1]
     elif len(list)==5:
         price,bid,expiration=list[-5]+list[-4]+list[-3],list[-2],list[-1]
     elif len(list)==6:
         price,bid,expiration=list[-6]+list[-5]+list[-4]+list[-3],list[-2],list[-1]
 
 
     price=price.split(':')
     price=price[-1]
     price=re.findall('\d+',price)
     price=int(price[0])
 
     bid=bid.split(':')
     bid=bid[-1]
 
     expiration=expiration.split(':')
     expiration=expiration[-2]+':'+expiration[-1]
     (exp_day,exp_time)=expiration.split()
     (year,month,day)=exp_day.split('/')
     (hour,min)=exp_time.split(':')
     year=int(year);month=int(month);day=int(day)
     hour=int(hour);min=int(min)
     expiration_time=datetime.datetime(year,month,day,hour,min)
     now=datetime.datetime.now()
     td=expiration_time-now
     return price,bid,td
     
 def search(qword='',auccat=0):
     host='http://search.auctions.yahoo.co.jp/search_rss?'
     qword=pykf.toeuc(qword,pykf.guess(qword))
     dict={
         'p':qword,
         'auccat':auccat,
         'alocale':'0jp',
         'acc':'jp'
     }
 #    query=host+qword+'&auccat=0&alocale=0jp&acc=jp'
     params=urllib.urlencode(dict)
     query=host+params
 ##    lines=urllib.urlopen(query)
 ##    print lines.read()
     d = feedparser.parse(query)
 #    print d.feed.title,d.feed.link
     for entry in d.entries:
         str=entry.description
         (price,bid,td)=desc_conv_pptd(str)
 #        if(bid!='-'):
         print entry.title
         print str
 #            print entry.modified
 #            print entry.link
 #           print entry.id
 #        print price,bid
 #        print td
 #        print str
 #        if(bid=='-' and  td.days==0 and td.seconds<10*3600):
 #            print entry.title
 #            print str
         
 
 if __name__ == '__main__':
     file='yah_ac.txt'
     lines=open(file,'r')
     for line in lines:
         cat=0
         word=''
         if(re.match(r'^#',line)):continue
         line=line.strip()
         if(re.search(r',',line)):
             (word,cat)=line.split(',')
         else :word=line
         search(word,cat)

yah_ac.txtに
 #   行頭#はコメント行
   tabやスペースを入れてもOK
    西原理恵子
みたいに書いておけば、情報を取得する。

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS