#!/usr/bin/env ruby require 'date' tvlisting_dir = "/mnt/part5/www/tvlistings/" html_cmd = "/home/kvh/bin/tvlistings/xmltv2html.rb" index_cmd = "/home/kvh/bin/tvlistings/create_index.rb" conf = "/home/kvh/.xmltv2htmlrc" files = Dir[tvlisting_dir + "20*.xml"] files.each { |f| fd = File.basename(f) # $stderr.print f, " ", File.stat(f).zero?,"\n" if File.stat(f).zero? then print "^^^ Zero file - Deleting #{f}\n" if File.delete(f) != 1 then print " Error deleting #{f}\n" end next end output_file = f.gsub(/.xml$/,".html") if File.exists?(output_file) and File.stat(output_file).zero? then print "^^^ Zero file - Deleting #{output_file}\n" if File.delete(output_file) != 1 then print " Error deleting #{output_file}\n" end next end output_file = f.gsub(/.xml$/,".html") if File.exists?(output_file) print "^^^ #{output_file} already exists.\n" next end fdd = fd.gsub(/.xml$/,"") prevday = nil nextday = nil # $stderr.print "#{fdd}\n" # d = Date.new(fdate[0,4].to_i, fdate[4,2].to_i, fdate[6,2].to_i) d = Date.new(fdd[0,4].to_i, fdd[5,2].to_i, fdd[8,2].to_i) nextday = d + 1 nextday_file = nextday.strftime("%Y-%m-%d") + ".html" prevday = d - 1 prevday_file = prevday.strftime("%Y-%m-%d") + ".html" # $stderr.print "prev day #{prevday}; #{prevday_file}\n" # $stderr.print "next day #{nextday}; #{nextday_file}\n" starttime = fdd[0,4] + fdd[5,2] + fdd[8,2] + "0000" stoptime = nextday.strftime("%Y%m%d") + "0000" # $stderr.print "starttime=#{starttime}\n" # $stderr.print "stoptime =#{stoptime}\n" run_me = html_cmd run_me += " --configfile=" + conf if File.exists?(conf) run_me += " < " + f + " > " + output_file run_me += " --urlprev=" + prevday_file if prevday_file run_me += " --urlnext=" + nextday_file if nextday_file run_me += " --starttime=" + starttime run_me += " --stoptime=" + stoptime print run_me,"\n" status = system(run_me) $stderr.print "Error ",status," occurred while running : ", run_me,"\n\n" if !status }