Advertisement
Guest User

Untitled

a guest
May 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'mysql2'
  3. require 'net/telnet'
  4.  
  5.  
  6. client = Mysql2::Client.new(:host => "localhost", :username => "root", :password => "xxxx", :database => "xtvd")
  7.  
  8. def programs_query(mysqlClient)
  9.  
  10. program_ids = Array[]
  11.  
  12. teams = Hash.new
  13. teams = {"bulls" => "SELECT id FROM program WHERE title like \"%NBA%\" and subtitle like \"%Bulls%\"",
  14. "blackhawks" => "SELECT id FROM program WHERE title like \"%NHL%\" and subtitle like \"%Blackhawks%\"",
  15. "cubs" => "SELECT id FROM program WHERE title like \"%MLB%\" and subtitle like \"%Cubs%\"",
  16. "bears" => "SELECT id FROM program WHERE title like \"%NFL%\" and subtitle like \"%Bears%\""}
  17.  
  18. results = mysqlClient.query(teams[ARGV[0]])
  19.  
  20. results.each do |row|
  21. program_ids.push(row["id"])
  22. end
  23. return program_ids
  24.  
  25. end
  26.  
  27. def stations_query(mysqlClient, program_ids)
  28.  
  29. date = Time.new
  30. statement_ids = ""
  31. station_ids = Array[]
  32.  
  33. i = 1
  34. for id in program_ids
  35. if i == program_ids.length
  36. statement_ids << "'"
  37. statement_ids << id
  38. statement_ids << "'"
  39. break
  40. end
  41. statement_ids << "'"
  42. statement_ids << id
  43. statement_ids << "', "
  44. i += 1
  45. end
  46.  
  47. results = mysqlClient.query("SELECT station FROM schedule WHERE startDate = " + date.strftime("%-m%e") + " and program IN (" + statement_ids + ")")
  48.  
  49. results.each do |row|
  50. station_ids.push(row["station"])
  51. end
  52. return station_ids
  53. end
  54.  
  55. def callsign_query(mysqlClient, station_ids)
  56.  
  57. statement_ids = ""
  58. callsigns = Array[]
  59.  
  60. i = 1
  61. for id in station_ids
  62. if i == station_ids.length
  63. statement_ids << id.to_s
  64. break
  65. end
  66. statement_ids << id.to_s
  67. statement_ids << ", "
  68. i += 1
  69. end
  70.  
  71. results = mysqlClient.query("SELECT callSign from station where id in (" + statement_ids + ")")
  72.  
  73. results.each do |row|
  74. callsigns.push(row["callSign"])
  75. end
  76. return callsigns
  77. end
  78.  
  79. def assign_channel(callsigns)
  80.  
  81. call_sign_data = {"CSN" => 685, "WLS" => 607, "WGN" => 609, "WCIU" => 606, "CLTV" => 616, "WPWR" => 608, "TNT" => 623, "TBS" => 622,
  82. "ESPN" => 681, "NBCSN" => 691, "WFLD" => 612, "WMAQ" => 605, "WBBM" => 602, "FS1" => 689}
  83. priority_stack = ["CLTV", "CSN", "WLS", "WGN", "WCIU"]
  84.  
  85. for call_sign in priority_stack
  86. if callsigns.to_s.include? call_sign
  87. return call_sign_data[call_sign]
  88. end
  89. end
  90. return call_sign_data[callsigns[0]]
  91. end
  92.  
  93. def send_command(channel)
  94.  
  95. command = "SETCH " + channel.to_s + " \r\n"
  96.  
  97. if channel.nil?
  98. quit()
  99. else
  100. telnet = Net::Telnet::new("Host" => "192.168.1.72", "Port" => 31339)
  101. telnet.puts(command)
  102. telnet.close
  103. exec "irsend SEND_ONCE receiver KEY_1"
  104.  
  105. end
  106.  
  107. end
  108.  
  109. programs = programs_query(client)
  110. stations = stations_query(client, programs)
  111. callsigns = callsign_query(client, stations)
  112. channel = assign_channel(callsigns)
  113. send_command(channel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement