Re: Previous APOD Page
Re: Previous APOD Page
- Subject: Re: Previous APOD Page
- From: Nigel Garvey <email@hidden>
- Date: Tue, 28 Aug 2012 09:53:42 +0100
Christopher Stone wrote on Mon, 27 Aug 2012 20:06:57 -0500:
>Hey Folks,
>
>Like many people I enjoy the APOD, and also like many people I often
forget
>to visit it daily.
>
>Enter Applescript.
Hi, Chris.
I've been using a script for many years which offers a 'choose from
list' selection of my favourite sites when I connect. I see its APOD
code still uses the Lévy/Hartman/Garvey method for getting the month
number!
>This script will jump backwards one day from the currently viewed APOD
>page, so you can quickly review what you missed.
>try
>
> tell application "Safari"
> tell front document
> set pageURL to quoted form of (get URL)
> set urlPath to do shell script "sed -E 's|[^/]+$||' <<< " &
pageURL
> set src to quoted form of (do shell script "tr '\\r' '\\n' <<< " &
>(quoted form of (get source)) without altering line endings)
> set previousApodURL to urlPath & (do shell script "echo " & src &
" |
>sed -n '/></p' | sed -E 's/[^\"]+\"([^\"]+).+/\\1/'")
> set URL to previousApodURL
> end tell
> end tell
>
>on error eMsg number eNum
[snip]
This works out the new URL by vanilla means:
set APODbaseURL to "http://apod.nasa.gov/apod/ap"
tell application "Safari" to set pageURL to URL of front document
if (pageURL starts with APODbaseURL) then
set dateNum to 20000000 + (text -11 thru -6 of pageURL)
if (dateNum > 20951506) then set dateNum to dateNum - 1000000
tell (current date) to set {day, year, its month, day, today} to {1, dateNum div 10000, dateNum mod 10000 div 100, dateNum mod 100, it}
tell (today - days) to set prevDateNum to year * 10000 + (its month) * 100 + day
tell application "Safari" to set URL of front document to ("http://apod.nasa.gov/apod/ap" & text 3 thru -1 of (prevDateNum as text) & ".html")
else
-- Your error here.
end if
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden