plamoni / SiriProxy

A (tampering) proxy server for Apple's Siri
GNU General Public License v3.0
2.12k stars 344 forks source link

Parse html text from body of webpage? #465

Closed tommyd75 closed 11 years ago

tommyd75 commented 11 years ago

I'm trying to have SiriProxy speak back what's written in the body of a .asp webpage. Does anyone know how to do that? I have this working, but it actually reads back all the code not the just the text in the body of the webpage. Here's what I have so far

listen_for /What's the status of the alarm/i do page = HTTParty.get('http://10.10.10.10/alarmstatus.asp').body rescue nil say page end

I think I'm close, but I can't figure it out???

This is what she reads back to me...

Untitled

I just want her to say "Disarmed"

plamoni commented 11 years ago
begin
    page = HTTParty.get('http://10.10.10.10/alarmstatus.asp').body
    status = /<body>\s*([\w]+)\s*<\/body>/.match(page)[1] || "Unknown" #If it fails to get the data or the data is malformed, it will say "Unknown"
    say status
rescue 
    #failed to get page -- maybe say "Unknown" or something.
end
tommyd75 commented 11 years ago

Thanks for your reply but I have another question. So I added this to my plugin and it crashed as soon as I started talking. What am I missing here? I'm sorry to be such a pain :(

listenfor /What's the status of the alarm/i do begin page = HTTParty.get('http://10.10.10.10/alarmstatus.asp').body status = /\s([\w]+)\s_<\/body>/.match(page)[1] || "Unknown" say status rescue

failed to get page -- maybe say "Unknown" or something.

end

tommyd75 commented 11 years ago

I know this is really not an issue with the plugin... But can anyone help me on this? I think I have figured it out but when I activate the plugin it starts it in Siri, but it just sits there. I get the feeling that there is something missing. With the above example, I'm just trying to get her to read back the body of local .asp web page. Sorry to be such a pest.

plamoni commented 11 years ago

You say it crashes, can you post the errors that it gives when it crashes?

tommyd75 commented 11 years ago

I was mistaken on that post. It actually sees the command and tries to execute it but it just hangs. I'm wondering if maybe there's any difference because I'm using port 81. I just so the local address I'm using is http://10.10.10.10:81/alarmstatus.asp').body

tommyd75 commented 11 years ago

Here's what I get when I ask "what's the status of the security system"

Processing 'what's the status of the security system'
Matches (?i-mx:what's the status of the security system)
Applicable states:
Current state:
Matches, executing block

The it just sits there and nothing happens, the phone just shows the little spinning light around the microphone.

Any ideas?

This exactly what I have in there.

listen_for /what's the status of the security system/i do
    begin
        page = HTTParty.get('http://10.10.10.10:81/alarmstatus.asp').body
        status = /<body>\s*([\w]+)\s*<\/body>/.match(page)[1] || "Unknown" 
        say status
    rescue 
        #failed to get page -- maybe say "Unknown" or something.
    end
end

I had put that second "end" in there because it was crashing as soon as I would activate Siri.

plamoni commented 11 years ago

That code wasn't really tested well. You might want to put something other than a comment in the rescue block.

tommyd75 commented 11 years ago

OK, I understand that. So now it answers back with whatever I have after the rescue, so I guess it's failing to get the info?

listenfor /what's the status of the security system/i do begin page = HTTParty.get('http://10.10.10.10:81/alarmstatus.asp').body status = /\s([\w]+)\s_<\/body>/.match(page)[1] || "Unknown" say status rescue say "Sorry Tom, I can't get that info for you right now" end end

tommyd75 commented 11 years ago

Got it working!! Thanks for streeting me in the wright direction. Here's what I'm using. Seems like that second "end" is needed otherwise it crashes.

listenfor /what's the status of the security system/i do begin page = HTTParty.get('http://10.10.10.10:81/alarmstatus.asp').body status = /\s([\w]+)\s_<\/body>/.match(page)[1] || "Unknown" say status rescue say "Sorry Tom, I can't get that info for you right now" end end

tommyd75 commented 11 years ago

Sorry to reopen this issue, but I wanted to continue on this little project. OK, so now it works as I described above, but I want to modify it. The actual webpage shows "The security system is Armed-Stay" But the above code only reads back the last word "Stay". How can I get it to read the whole sentence or page? I tried just using only the \w expression but that doesn't work.

tommyd75 commented 11 years ago

Anyone??

elvisimprsntr commented 11 years ago

Does the alarm you are using have a REST API you can retrieve status information rather than trying to parse the HTML page?

tommyd75 commented 11 years ago

I'm actually using Homeseer to talk to the alarm via serial cable. So the controlling is happening from Homeseer.

elvisimprsntr commented 11 years ago

Seems like you might be taking the hard road. Have you considered following trails others have already blazed? http://www.youtube.com/watch?v=5durOpUgarw https://github.com/espenhogbakk/siriproxy-homeseer

It also might be more appropriate to post your questions on the HS forums since your questions are not specific to siriproxy itself. http://board.homeseer.com/showthread.php?t=151349

tommyd75 commented 11 years ago

I've already asked this same question on the Homeseer forums and on the Github listed below.

Using these instructions I'm able to get status of individual devices.

https://github.com/espenhogbakk/siriproxy-homeseer

I'm able to see status of separate devices using for example this. Just entering this into a browser "http://10.10.10.10/tenHsServer/tenHsServer.aspx?t=ab&f=GetDevice&d=K8" which shows me text on a webpage like this. "K8:Living room:Living Room Lights:Lamp Module w Status:0:LIGHTS:True:3:0::989::2/27/2013 3.00.00 AM;"

My question is do you know of a way to parse that info if all I want is a certain area like the part that says "True" I'm trying to incorporate this into a SiriProxy plugin like this for example but i don't know how to get it to read that back. Here's what I'm trying to do.

listen_for /What's the status of the living room light/i do page = HTTParty.get('http://10.10.10.10/tenHsServer/tenHsServer.aspx?t=ab&f=GetDevice&d=K8').body rescue nil reply = JSON.parse(page) rescue nil say "The status of the living room light is currently #{reply["DON'T KNOW WHAT TO PUT HERE"]}"

elvisimprsntr commented 11 years ago

add a puts reply to see what the parsed response looks like. then you can decide what methods you need to use to parse the device status.

Again, your questions are probably more appropriate for the HS or Cocoontech forums. If you need help specifically with Ruby you can post your questions on StackOverflow.

elvisimprsntr commented 11 years ago

closed due to inactivity