Open a webpage on LAN then kill it

Posted on
Sat Mar 19, 2016 8:20 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Open a webpage on LAN then kill it

I've got a webpage on my LAN that calls an external (internet) API for about 15 seconds.

I don't need to see the page as it emails me success or failure messages when it runs.

Can someone who knows OS X more than I do help me call this page in an Action?

I've got a non-embedded python script that calls:

Code: Select all
subprocess.Popen('open http://ip_address/folder/cmd.php?action=stuff',shell=True);

Can I get this to close/kill/terminate after 30 seconds so it's not hanging around; I might call this action (there's 4 commands I can give it) several times per day which I guess will just stay open? I don't need a graceful action - just kill it!

Peter

Posted on
Sat Mar 19, 2016 8:41 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Open a webpage on LAN then kill it

Try something like:

Code: Select all
subprocess.Popen('open http://ip_address/folder/cmd.php?action=stuff; sleep 30; exit',shell=True);

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Mar 19, 2016 8:54 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Open a webpage on LAN then kill it

I think that's just sleeping and killing the shell process - not the safari app that opens the URL.

Can I do pid = .... Followed by process.close(pid) or something like that?


Sent from my iPhone using Tapatalk

Posted on
Sat Mar 19, 2016 8:56 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Open a webpage on LAN then kill it

TBH, I'd be happy force-quitting Safari - I never consciously leave it open as the server is headless.


Sent from my iPhone using Tapatalk

Posted on
Sat Mar 19, 2016 9:25 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Open a webpage on LAN then kill it

Do you actually need Safari to open the URL? Are you looking at the output? Try using curl in a Terminal window with the same URL. Does it do what you need?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Mar 19, 2016 9:29 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Open a webpage on LAN then kill it

I wondered the same as I posted my last reply... :-)


Sent from my iPhone using Tapatalk

Posted on
Sat Mar 19, 2016 9:30 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Open a webpage on LAN then kill it

I would actually look at using the Python Requests module to do the web page fetch directly from a Python script. No shell at all.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Mar 19, 2016 9:32 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Open a webpage on LAN then kill it

It will get stopped by Indigo though - more than 10 seconds.


Sent from my iPhone using Tapatalk

Posted on
Sat Mar 19, 2016 9:34 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Open a webpage on LAN then kill it

External Python script, not an embedded script.

Or go whole hog - write a plugin that specifically deals with this external API you're using. ;)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Mar 19, 2016 9:40 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Open a webpage on LAN then kill it

There's already a plugin for it - Nissan Leaf - but currently Nissan have disabled the API.

The temporary method I'm using is POSTing to a website that has somehow screen-scraped the live Nissan pages and is thus still working.

Once Nissan fix their security leak and the API, the Nissan Leaf plugin will be updated accordingly. :-)


Sent from my iPhone using Tapatalk

Posted on
Sat Mar 19, 2016 9:48 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Open a webpage on LAN then kill it

Where does he 15 seconds come from? Does it take that long for the page to display? Or does it never finish and you have to cancel the fetch? Writing an external Python or shell script that self terminates is probably the best way.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Mar 19, 2016 9:50 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Open a webpage on LAN then kill it

It 'rings up' the car over 2G network to send the command, then returns with success or failure in a JSON blob.

If I don't need success/failure I can ignore it once the command has initialised.


Sent from my iPhone using Tapatalk

Posted on
Sat Mar 19, 2016 9:59 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Open a webpage on LAN then kill it

Use curl with a short -m (--max-time) option so it returns right away. Maybe something like:

Code: Select all
subprocess.call(["/opt/local/bin/curl", "-m", "5", "http://ip_address/folder/cmd.php?action=stuff");

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests