norcoscia wrote:Hi Terry, sorry for what I'm sure is a dumb question but when you say - save the code - do you mean as an HTML file on your HA PC - and when you say "run webkit2png against it" do you just put the webkit line in an indigo schedule as a python script - when I do that - it does not like it - and when I run from the terminal window I just get a picture of the HTML text like it is a snapshot of the text pad text. - I think I need some help - if you don't have time no worries - I can always just look outside
Yep, take that come and save it
something.html on your PC, it doesn't have to be your HA PC at this point, since we're just playing around. Use a good text editor like Text Wrangler, Sublime Text, or any other you're familiar with, just not the Apple-provided TextEdit, it does strange things to pure text files. If you're playing on a Windows PC, notepad.exe is fine - BUT - I'm not sure how the webpages will render on Windows, probably best to stick with a Mac/Safari for experimentation.
Anyway, once you have it saved as a plain text (html) file on your Mac, and named
something.html, double-click on it so that it opens in Safari (assuming Safari is your default web browser). You should see some ads, or other strange garbage text flash up for a few seconds while the page loads, and then you should see the 10-day forecast. (That few seconds of 'garbage' is why we delay webkit2png 5 seconds before taking screenshot.)
Now assuming that the result of the above is the 10 day forecast for Birmingham, Alabama, as in the image I linked earlier - that part is working. You just need to change the location. Thats done in the line:
- Code: Select all
https://www.wunderground.com/us/al/birmingham/zmw:35201.1.99999#div.plots.has-header
in the html file. Edit the HTML file and change that line (everything after the
https://, and before the #div.plots.has-header to reflect your area. As I mentioned before, I got that URL by clicking on "Full Forecast" from the main WU website, then clicking on the "Forecast" tab on the next page. Look at the URL that Safari is and copy/paste that into the HTML file, replacing my Birmingham info. It's important to leave the #div.plots.has-header piece in there though, thats the HTML DIV that actually holds the 10 Day forecast on WU's webpage.
Save your changes and open it in Safari again. This time you should see your local info instead of mine. Assuming that works, you can move on to creating a png image from that webpage. Thats where webkit2png comes in. You run it from a terminal and point it at the html file you just created. So, the following command typed at a terminal window:
- Code: Select all
webkit2png -C --clipwidth=800 --clipheight=400 --scale=1 file:///Users/terry/Desktop/wufc.html --transparent --delay=5 -o wu10day
is broken down like this:
webkit2png -- the command
-C -- This switch tells webkit2png to produced a "clipped" png, to the specifications we'll specify
--clipwidth=800 --clipheight=400 -- the size to crop the image. Note that this is a crop, and not a scale.
--scale=1 -- one-to-one image scale, adjust this is you want to zoom/shrink the resultant png image.
file:///Users/terry/Desktop/wufc.html -- the path to the html file you created, adjust the path & file to fit your situation
--transparent -- IF POSSIBLE, webkit2png will create the image with a transparent background. This isn't always possible and depends on how the donor webpage was coded.
--delay=5 -- Load the page, but wait 5 seconds before creating the png. This give the webpage time to load, change this depending on what you're grabbing, it'll take some trial-and-error
-o wu10day -- output png name. This tell webkit2png to create a file named wu10day. NOTE: it will append "-clipped.png" to the name, resulting in "wu10day-clipped.png"
If you have the HTLP file producing a satisfactory webpage in the first step, and if you adjust the parameters in the webkit2png command above to fit your situation, you should then have a nice PNG in the current directory from where you're running webkit2png. Assuming all of that works, you're ready to transfer the process to Indigo.
Move the html file to wherever you're storing your Indigo scripts. mine are located in /Library/Application Support/Perceptive Automation/Indigo 7/Scripts/", but you can have it pretty much anywhere it's convenient for you and Indigo can "see" it.
Now, I like to specify absolute paths to programs and files, that tends to make for long command when files are buried deeply. So mu usual practice is to consolidate similar commands into a shell script thats eaiser to reference. As an example, the command that generates my weather image looks like this due to the long absolute paths:
- Code: Select all
/usr/local/bin/webkit2png -F /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/Scripts/forecast2.html --transparent -D /Library/Application\ Support/Perceptive\ Automation/Indigo\ 7/IndigoWebServer/static/ -o forecast --delay=3
So, what I did, and recommend you do as well, is in the same folder that you place your html file, also create a text file called getweather.sh or similar (just make sure to have the ".sh" on there.) and in that .sh text file, place two lines. the first line should be:
- Code: Select all
#!/bin/sh
which is standard in a shell script and simply tells the command processor where to find the UNIX shell. The second line should be you're webkit2png command that you created above. Just up-arrow in the terminal and copy/paste it into the file. AS I did in my long webkit2png command above, be sure to type out the full path to the html, file, the directory where your storing the file (the -D switch in my command above) and the path to webkit2png itself (probably usr/local/bin/webkit2png). Save that and then back at the terminal, change to the directory where you have the script stored and type
- Code: Select all
chmod a+x ./filename.sh
where filename.sh is the shell script you just created. IF that doesn't return an error, at the terminal type ./filename.sh and webkit2png should run with all of your paths and switches, producing another image after a few seconds.
Assuming all of that works, all you need to do now is create a schedule in Indigo to run that shell command at whatever frequency you desire. Here's mine:
- Screen Shot 2017-08-15 at 11.38.28 AM.png (215.61 KiB) Viewed 3585 times
- Screen Shot 2017-08-15 at 11.40.40 AM.png (272.64 KiB) Viewed 3585 times
Hope this helps, I know it seems like a lot, but just break it down into the individual pieces and you'll get it!
Terry