Monday, October 7, 2013

Picture of the Day - Part 3

Continuing on from Part 1 and Part 2.

I wasn't happy with the results of the Automator workflow.
It was nice to have a play around and see what it could do, but it seemed that I was wanting to do some more advanced functions, like text append, that just weren't available or easy in Automator.

So I used my Bash scripting power to come up with another approach that gave me the flexibility that I needed.

 
#!/bin/bash
#build up the url
MYURL="http://en.wikipedia.org/wiki/Template:POTD/";
DATE=`date +%Y-%m-%d`
MYURL=$MYURL$DATE

temp=$(/opt/local/bin/lynx -dump -nonumbers -listonly -image_links $MYURL | grep en\. | grep -E "(.jpg|.JPG)" | grep -v thumb)

temp2=$(/opt/local/bin/lynx -dump -nonumbers -listonly -image_links $temp | grep upload | grep -E "(.jpg|.JPG)" | grep -v thumb | uniq)

#get the image
/opt/local/bin/wget --no-check-certificate -O /Users/jono/Documents/Backgrounds/1.jpg $temp2

To break it down,
First I would build up the URL in the form that I needed.

Then I would use the command line browser lynx to grab the image links out of that URL. I would filter the results on some text like 'en.' (to make sure I hit en.wikipedia.org) and '.jpg' (to make sure I just got jpg results) but I didn't want any URLs returned with the text 'thumb' - as they were thumbnails, so I used the grep filter 'grep -v thumb' to NOT include those results.

So I should now have the URL of the wikipedia file document in the form
http://en.wikipedia.org/wiki/File:xxxxxxxxxx.jpg

That file document, again had just a larger version of the thumbnail on that page, but it linked to the original higher resolution image.

So I ran lynx again, applied pretty much the same filters, and made sure that I only had unique results (the pipe to uniq command)

I now have the link to the full resolution uploaded file and I use the command wget to save it straight to the location I wanted named as the filename I wanted (1.jpg)

No need to save it and then move and rename, like I tried to do in Automator.

Now my geektool geeklet that is looking in that location every 5 secs or so kicks in and changes the desktop background to the newly download picture.

Now you can just set that up as a login script and you can have dynamic fresh Picture of the Day each time you log in.

Sunday, October 6, 2013

Picture of the day - Part 2

Picking up where Part 1 left off, I tried to do a better way to create a picture of the day for Geektool to use.

 As Wikipedia picture of the day was in the standard format

http://en.wikipedia.org/wiki/Template:POTD/yyyy-mm-dd 

I decided to just grab what I needed.
At first I researched using variables in Automator, but it seem to handle appending text,all the forums had people creating Applescripts to build up dynamic text.

So I whipped up the applescript:

 set myURL to "http://en.wikipedia.org/wiki/Template:POTD/"
 
 set myshort to short date string of (current date)
 set myday to items 1 through 2 of myshort
 set mymonth to items 4 through 5 of myshort
 set myyear to items 7 through 10 of myshort
 
 set myURL to myURL & myyear & "-"
 set myURL to myURL & mymonth & "-"
 set myURL to myURL & myday
 
 return myURL

in order to get constancy on the date I had to force the short dat to be 2 digits\2digits\4 digits
You can do this in System Preferences > Language and Text > Formats > Customize
that gave the short date the format 01/01/1970 where I could use the "to items 1 through 2" to pick it apart so I could use it as I wanted.

So I came up with what I hoped was a working workflow:

Except it didn't work.
It dumped the files to folder abc123 okay, again it had the extra images I didn't need as well as the POTD in .jpg format.
Putting in a 'view results' into each step of the workflow, I could see what was going on.
It seems that my 'Filter Finder Items' wasn't working as I expected. It didn't return anything to be renamed, and then moved. Maybe I wasn't using it properly and selecting Desktop > abc123 properly.
Maybe I could work it out, but I still wasn't happy that the Save Images was only getting the thumbnail of the Picture of the Day.

How I solved it in a way I was happy with will be part 3.

Picture of the day - Part 1

Okay, so I use the great app Geektool to change/show some desktop pictures.

I have Geektool configured to look in my backgrounds folder for a file 1.jpg and display it as my background picture. I thought it would be cool if that picture changed daily.

So what site has a great looking picture of the day? Wikipedia of course.

So my idea was to use Mac OS X Automator to follow this workflow:

Use the main wikipedia URL
Get the links from the page
Filter them down as the POTD always contained http://en.wikipedia.org/wiki/Template:POTD/ then todays date
Get the contents of the page
Save images

So I created this workflow, which worked okay.


That dumped the files to the folder abc123 on my desktop but it wasn't efficient. It would grab all the other images like the wikipedia logo as well as the picture of the day as small thumbnails.
I tried to use automators various other finder functions to move and rename, but I didn't have much luck.

I thought that I could do better by getting only the exact image I wanted at the size I wanted, so see what else I tried in Part 2.