Created
December 29, 2014 21:59
-
-
Save alext/7c8cf1fc9d78d0dfd560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'rexml/document' | |
require 'mysql2' | |
require 'date' | |
HOME_CONFIG = "#{ENV['HOME']}/.mythtv/config.xml" | |
ETC_CONFIG = "/etc/mythtv/config.xml" | |
if File.exist?(HOME_CONFIG) | |
file = HOME_CONFIG | |
elsif File.exist?(ETC_CONFIG) | |
file = ETC_CONFIG | |
else | |
raise "No config.xml found at #{HOME_CONFIG} or #{ETC_CONFIG}" | |
end | |
doc = REXML::Document.new(File.open(file, 'r')) | |
client = Mysql2::Client.new({ | |
:host => doc.elements.to_a("//DBHostName").first.text, | |
:port => doc.elements.to_a("//DBPort").first.text.to_i, | |
:username => doc.elements.to_a("//DBUserName").first.text, | |
:password => doc.elements.to_a("//DBPassword").first.text, | |
:database => doc.elements.to_a("//DBName").first.text, | |
}) | |
File.open("channels_#{Date.today.to_s}.sql", 'w') do |f| | |
client.query("SELECT * FROM channel ORDER BY chanid").each do |row| | |
next if row["xmltvid"].to_s =~ /\A\s*\z/ | |
f.puts "UPDATE channel SET xmltvid='#{row["xmltvid"]}', useonairguide=0 WHERE callsign = '#{row["callsign"]}';" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment