| 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 |
| 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 | |
| | 90 | |
| | 91 | def 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 |
| | 107 | end |