Lookup data using ruby and execute bash with data
What I want to do is to use Siriproxy to control my Sky+ box (which I have
working to a degree)
Sky uses channel numbers but converts them to hex numbers that it
understands. I have the file with all channel numbers, the channel names
and the hex codes. I want to make a ruby script that looks up the hex of
the channel number I say and then send it as part of a command to the sky
box through a bash script (unless there is an easier way).
I currently have a very crude and long winded way of doing it that
involves multiple bash scripts creating .txt files etc but I'm sure there
must be a better way.
EDIT with more info:
#demonstrate capturing data from the user (e.x. "Siri proxy number 15")
listen_for /change the channel number ([0-9,]*[0-9])/i do |number|
#say "Changing the Channel to #{number}"
f = File.new("/root/SiriProxy/sky/channel.txt", "w")
f.puts "SKY#{number}"
f.close
#system("echo [Info - Plugin Manager] Channel number #{number} stored to
sky/channel.txt")
system("sh /root/SiriProxy/sky/change_channel.sh")
File.open('/root/SiriProxy/sky/channel_name.txt').each_line{ |s|
#puts s
say "I've changed the channel to #{s}"
}
request_completed
end
Then there is the bash script:
#!/bin/bash
for line in `cat /root/SiriProxy/sky/channel.txt`
do
cat /root/SiriProxy/sky/channel_numbers.txt | grep $line | cut -d" " -f3
> /root/SiriProxy/sky/hex.txt
done
for line in `cat /root/SiriProxy/sky/channel.txt`
do
cat /root/SiriProxy/sky/channel_numbers.txt | grep $line | cut -d" " -f2
> /root/SiriProxy/sky/channel_name.txt
done
for line in `cat /root/SiriProxy/sky/hex.txt`
do
(echo 'POST /SkyPlay HTTP/1.1
SOAPACTION: "urn:schemas-nds-com:service:SkyPlay:2#SetAVTransportURI"
Content-Type: text/xml; charset=utf-8
Content-Length: 399
<?xml version="1.0" encoding="utf-8"?><s:Envelope
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:SetAVTransportURI
xmlns:u="urn:schemas-nds-com:service:SkyPlay:2"><InstanceID>0</InstanceID><CurrentURI>xsi://'$line'</CurrentURI><CurrentURIMetaData>NOT_IMPLEMENTED</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>')
| nc -n 192.168.1.82 49153
done
Thanks for any help, this is a little above my novice status!
No comments:
Post a Comment