root/platform/pragger/Publish/nicovideo_rank.rb @ 21226

Revision 10829, 1.0 kB (checked in by yasuyuki, 6 years ago)

HTMLテンプレートファイルを分離するよう修正 1

Line 
1## publish nicovideo mylisted avarage ranking
2##
3## - module Publish::nicovideo_rank
4##   config:
5##     n: display ranking number.
6##
7## Copyright (C) 2007-2008, INOUE Yasuyuki <inoue.yasuyuki0@gmail.com>
8## Original version is written by TADA Tadashi <sho@spc.gr.jp>
9## You can redistribute it and/or modify it under GPL3 or any later version.
10
11require 'erb'
12require 'cgi'
13require 'pp'
14
15def nicovideo_rank(config, data)
16        rank_data = data.sort {|a, b| (a['viewed'] == 0 ? 0 : a['mylisted'] / a['viewed']) <=> (b['viewed'] == 0 ? 0 : b['mylisted'] / b['viewed'])}.reverse
17        result_html = []
18        now = Time::now
19        begin
20    open( "#{config['fetch_date']}" ) {|f| now = YAML.load( f ) }
21        rescue Errno::ENOENT
22        end
23  template = nil
24 
25  open("#{config['template']}") {|f| template = ERB::new(f.read)}
26 
27        yesterday_root = (now - 24 * 60 * 60).strftime("/%Y/%m/%d/")
28        tommorow_root = (now + 24 * 60 * 60).strftime("/%Y/%m/%d/")
29       
30        (0..2).each do |page|
31                break if page * config['by_page'].to_i > rank_data.length
32                result_html << template.result(binding())
33        end
34        result_html
35end
Note: See TracBrowser for help on using the browser.