Changeset 7628 for platform

Show
Ignore:
Timestamp:
03/07/08 21:08:57 (5 years ago)
Author:
yasuyuki
Message:

platplatform/pragger/Feed/nicovideo_rank.rb: リファクタリング/ランキング登録済み動画を再度ランキング登録対象リストに登録していた問題を修正 21

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/pragger/Feed/nicovideo_feed.rb

    r7594 r7628  
    3333                        key = (v / 'a').first['href'] 
    3434                        key = base + key  
    35  
    36       cache = {} 
    37       cache['link'] = key 
    3835      thumb = (v/ 'img.cmn_thumb_img').first 
    39       cache['title'] = thumb['alt'] 
    40       cache['viewed'] = (v / 'p.TXT10 strong')[1].inner_html.tr(',', '').to_f 
    41       cache['mylisted'] = (v / 'p.TXT10 strong')[3].inner_html.tr(',', '').to_f 
    42       cache['uploaded_at'] = items[key] ? items[key].date : updated_at 
    43       cache['updated_at'] = updated_at 
    44       raw_items[key] = cache 
    4536 
    4637                        if items[key] then 
    47                           next 
     38        raw_items[key]['updated_at'] = updated_at if raw_items[key] 
     39      else 
     40        item = RSS::RDF::Item::new 
     41        item.link = key 
     42        if thumb then 
     43          item.title = thumb['alt'] 
     44          item.description = "<a href=\"#{key}\"><img border=\"0\" src=\"#{thumb['src']}\"/></a><br/>" 
     45        else 
     46          item.title = (v / 'p.TXT12 a').first.inner_html 
     47        end 
     48        item.description += (v / 'p.TXT12' ).inner_html.gsub( /<.*?>/, '' ) 
     49        item.date = updated_at 
     50        items[key] = item 
     51        cache = {} 
     52        cache['link'] = key 
     53        cache['title'] = thumb['alt'] 
     54        cache['viewed'] = (v / 'p.TXT10 strong')[1].inner_html.tr(',', '').to_f 
     55        cache['mylisted'] = (v / 'p.TXT10 strong')[3].inner_html.tr(',', '').to_f 
     56        cache['uploaded_at'] = items[key] ? items[key].date : updated_at 
     57        cache['updated_at'] = updated_at 
     58        raw_items[key] = cache 
    4859                        end 
    49  
    50                         item = RSS::RDF::Item::new 
    51                         item.link = key 
    52                         if thumb then 
    53                                 item.title = thumb['alt'] 
    54                                 item.description = "<a href=\"#{key}\"><img border=\"0\" src=\"#{thumb['src']}\"/></a><br/>" 
    55                         else 
    56                                 item.title = (v / 'p.TXT12 a').first.inner_html 
    57                         end 
    58                         item.description += (v / 'p.TXT12' ).inner_html.gsub( /<.*?>/, '' ) 
    59                         item.date = updated_at 
    60                         items[key] = item 
    6160                end  
    6261        end 
     
    6766        return_items = items.values.sort {|a,b| a.date == b.date ? (a.link.scan(/\d+$/)[0].to_i <=> b.link.scan(/\d+$/)[0].to_i) : (a.date <=> b.date) }.reverse 
    6867         
    69         if config['cache'] then 
    70           oldest_cache_item = items.size > 1200 && return_items[1200].link.scan(/\d+$/)[0].to_i 
    71                 cache_items = (items.size > 1200) ? items.reject {|a, b| b.link.scan(/\d+$/)[0].to_i < oldest_cache_item} : items.dup 
    72                 open( config['cache'], 'w' ) do |f| 
    73                         YAML.dump(cache_items, f) 
    74                 end 
    75         end 
    76         if config['rank'] then 
    77                 open( "#{config['rank']}.dump", 'w' ) do |f| 
    78                         YAML.dump(raw_items, f) 
    79                 end 
    80                 open( "#{config['rank']}.last_fetched", 'w' ) do |f| 
    81                         YAML.dump(updated_at, f) 
    82                 end 
    83         end 
     68  save(config, items, return_items, raw_items, updated_at) 
     69   
    8470        return_items 
    8571end 
     
    10288  return items, raw_items 
    10389end 
     90 
     91def save(config, items, return_items, raw_items, updated_at) 
     92        if config['cache'] then 
     93          oldest_cache_item = items.size > 1200 && return_items[1200].link.scan(/\d+$/)[0].to_i 
     94                cache_items = (items.size > 1200) ? items.reject {|a, b| b.link.scan(/\d+$/)[0].to_i < oldest_cache_item} : items.dup 
     95                open( config['cache'], 'w' ) do |f| 
     96                        YAML.dump(cache_items, f) 
     97                end 
     98        end 
     99        if config['rank'] then 
     100                open( "#{config['rank']}.dump", 'w' ) do |f| 
     101                        YAML.dump(raw_items, f) 
     102                end 
     103                open( "#{config['rank']}.last_fetched", 'w' ) do |f| 
     104                        YAML.dump(updated_at, f) 
     105                end 
     106        end 
     107end