Friday, April 20, 2018

#1 2017-12-17 05:35:11 am

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 550
Website

Daily new wallpapers

In the past I was able to get every day a new wallpaper from National Geo. 
Unfortunately Bing and Ng coded that stuff so it's not easy to fetch the data to download. The code below was tweaked but not written by myself. I'd give credits but it's long time ago, so I can't remember anymore the original source sad

Applescript:

set WallPaper to POSIX path of (path to temporary items folder from user domain as text)
set cmd to "#!/bin/sh\ncd " & WallPaper & ";\ncurl [url]http://photography.nationalgeographic.com/photography/photo-of-the-day/[/url] -o pod\n# look for wallpaper version\nif (curl `cat pod | tr '\"' '\n' |grep -B 1 'Download wallpaper' | head -1` -o pod2) then\n\tcat pod2 | tr '\"' '\n' |grep -oh 'http://.*exposure.*.jpg' |head -1 | sed 's/0_360x270/0_1440x900/'\n\ta=`cat pod2 | tr '\"' '\n' |grep -B 4 -A 4 'Desktop Wallpaper' | grep '.jpg' | sed 's/0_1600x1200/0_1440x900/'`\n\tcurl '[url]http://photography.nationalgeographic.com/[/url]'$a -o national-geographic-photo-of-the-day.jpg;\nelse\n\t# download the image from here --- in case it is not a wallpaper\n\ta=`cat pod|tr '\"' '\n' |grep -A 20 \"primary_photo\"|grep nationalgeographic.com`\n\tcurl 'http:'$a -o national-geographic-photo-of-the-day.jpg;\nfi\n"

Offline

 

#2 2017-12-17 06:37:59 pm

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4529

Re: Daily new wallpapers

That first URL returns a page saying that the URL has changed permanently to "http://www.nationalgeographic.com/photography/photo-of-the-day/" (ie. "www" instead of "photography.) The new URL opens in my browser, but doesn't send anything when curl-ed in that way.


NG

Offline

 

#3 2017-12-25 07:14:41 am

Frankv
Member
From:: Amsterdam, NL
Registered: 2017-09-11
Posts: 5

Re: Daily new wallpapers

I'm not sure how your script works, but maybe you can repair it with the below code:

Applescript:

curl -L [url]http://www.nationalgeographic.com/photography/photo-of-the-day[/url] | grep '<meta property=\"og:image\" content='|awk '{print $3}'| awk -F'\"' '$0=$2'

If that doesn't work, this will download the photo and store it in the Downloads folder.

Applescript:

set pictureURL to do shell script "curl -L [url]http://www.nationalgeographic.com/photography/photo-of-the-day|[/url] grep '<meta property=\"og:image\" content='|awk '{print $3}'| awk -F'\"' '$0=$2'"
do shell script "curl " & pictureURL & " -o ~/Downloads/photo-of-the-day.jpg"

In both snippets you must remove [ url ] and [ /url ] to get it to work in the Applescript editor.

Last edited by Frankv (2017-12-25 07:23:10 am)

Offline

 

#4 2017-12-26 10:25:15 am

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 550
Website

Re: Daily new wallpapers

Francv, I appreciate your thought.
Just as said before, both websites wrapped their daily pictures around a code, so a normal Curl doesn't work. I mean, of course you can try but all you get will be an empty file. Anyway.
Merry Christmas!

Offline

 

#5 2017-12-26 10:46:07 am

Frankv
Member
From:: Amsterdam, NL
Registered: 2017-09-11
Posts: 5

Re: Daily new wallpapers

I know, but my code does find the link Curl can use to download the Photo of the day.

In my previous message this forum has added additional tags to my code, so both code snippets don't work. The curl command is (one line):

curl -L 'http://www.nationalgeographic.com/photo … of-the-day'|grep
'<meta property=\"og:image\" content='|awk '{print $3}'| awk -F'\"' '$0=$2'

This also changed the link in the code:
Copy the correct link to be used from here

Last edited by Frankv (2017-12-27 01:37:29 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)