PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: firefox /curl /whatever  (Read 502 times)

raymw

  • Senior Member
  • ***
  • Posts: 430
firefox /curl /whatever
« on: November 10, 2021, 11:52:18 AM »

Hi, a bit off topic, but maybe someone has an idea.
I'm trying to access text on a web page, and if ia word matches one in my list, then it will play a sound file on my local pc.
The situation is the web page is the interface to my 3d printer, accessed via wifi. The printer is in another room, and I would like a sound to happen on my local pc when an error occurs, or print ends, say.  I was looking into having a command line (windows 10) or a batch file, to every minute or so, save the page, do a word search, and if a key word is found to take the appropriate action.
Curl will not handle the css/java, Firefox, will do it nicely, you can save the page as text, but not afaik from the command line. This is an area that I'm not familiar with, so any help appreciated. It was  only today I found curl, and realised firefox could run from command line.
Any suggestions welcomed.
Logged

philbar

  • Little Newbie
  • *
  • Posts: 31
Re: firefox /curl /whatever
« Reply #1 on: November 11, 2021, 10:23:36 AM »

Maybe not the simplest idea, but WinFBX has a CWinHttpRequest Class that you can use to connect to a website, request a page, and receive the page as a string. You could then search the string for your key words. It could be a fairly short program that you run periodically, or it could lurk in the background and activate itself on a timer. I haven't actually tried this, so I can't say if there are any gotchas.
Hey, that would make it on topic.

Logged

raymw

  • Senior Member
  • ***
  • Posts: 430
Re: firefox /curl /whatever
« Reply #2 on: November 11, 2021, 02:18:14 PM »

Thank. It is surprising how complicated simple things can become. I actually, after pushing the software developers, found that there is a web based text file written, not sure how often, but giving the latest status of the printer. This is in plain text and curl will find it and save as a text file. I've found a couple of key words in the state field, -'completed' and 'paused', there maybe more, but nobody has said. I've written a couple of bat files to play m4a files (never heard of that format, but seems to be what w10 sound recorder defaults to), and found that *c:vlc --qt-start-minimized --play-and-exit soundFilename " will play them in the background, without flashing media players on the screen. My current problem, is that having done a simple gui, with  a start and stop button and a text box for the time period, I've forgotten how to deal with sleep. i.e. hitting the start button reads the file, speaks message if paused or completed, goes to sleep for a while, wakes up and repeats. The snag is, that other than closing the window, I can't break out of the sleep loop.  I'm getting mixed up with micro-processor programming, where you can sleep until an interrupt. I was hoping that hitting the stop button would interrupt the 'sleep loop', and allow the time settings to be changed/whatever. All that happens is that the whole form gets 'greyed out', it is not responding (but still runs the loop). There is a simple answer, i just can't think of it.
Logged

raymw

  • Senior Member
  • ***
  • Posts: 430
Re: firefox /curl /whatever
« Reply #3 on: November 11, 2021, 03:27:22 PM »

Another annoyance, is that running a cmd line bat task, opens the cmd window. Not sure if i can get around that
Logged

SeaVipe

  • Senior Member
  • ***
  • Posts: 437
  • Windows 10
Re: firefox /curl /whatever (SLEEP)
« Reply #4 on: November 11, 2021, 06:14:37 PM »

Hi Ray, Not sure how helpful this is but I've used the TIMER function a few times:
Code: [Select]
'' Example of using TIMER function
'' Note: see text about correct waiting strategies
Dim Start As Double
Print "Wait 2.5 seconds."
Start = Timer
Do
    Sleep 1, 1
Loop Until (Timer - Start) > 2.5
Print "Done."
In one usage I was checking for an event to exit the Do and in another version, the loop waited for a keystroke.
Logged
Clive Richey
You're Either Part Of The Solution, Or You're The Problem.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!

raymw

  • Senior Member
  • ***
  • Posts: 430
Re: firefox /curl /whatever
« Reply #5 on: November 12, 2021, 06:20:43 AM »

Thanks, I'll try that. I thought that the sleep, when used, sort of turned off the process and released the cpu/etc, but using timer kept it all running. I guess it doesn't matter so much with the more modern multicore cpus.
Instead of playing back a recorded message of me saying 'printer paused', I thought I'd use narrator or something to read a small text file containing the phrase. There seems to be problems with all the text file to speech systems out there, at least for me. Back in the day of the Tandy (radio shack) trs80, i made a speech unit, parallel printer interface, fed it a file of phonemes, simple.
Logged

raymw

  • Senior Member
  • ***
  • Posts: 430
Re: firefox /curl /whatever
« Reply #6 on: November 12, 2021, 07:37:31 AM »

I remember something about having to use something like a refresh, but have found that AfxDoEvents in the loop will let it break out of the loop when loop finishes., but not immediately.  It can take a while running the bat files. Not sure if possible to run them starting in a minimised cmd window. I've used the timer loop, as suggested
Logged