Download URL pdf file (without a date) - a tricky question?

Hello,

Need to make a Automator/ Apple script that can download a pdf from a website. Normaly when there is a date in the URL it’s no problem, you can easily do that with Replace Date Holder from www.advenio.com ( http://automatoractions.com/files/replacedateplaceholders1.1.1.html )

This time it’s a pdf file that is only available on ; mo, tue, wed, thu, fri

So today (wed) the pdf is called 25.pdf. Thu will be called 26.pdf, Friday 27.pdf and then monday it will be called 28.pdf etc Think you got te point.

Is this possible with Applescript?

Thanks

Bob

Hi bob,

is there any math relation between the URL’s number and the date
or is it just a consecutive number?

Sure it’s possible, but I don’t get the naming scheme. Today is the 14th, but the script is called 25.pdf. Is it always Monday = 23, Tuesday = 24, Wednesday = 25, etc.?

If the numbering is always as I asked:


set FileName to ((21 + (weekday of (current date))) as text) & ".pdf"
--> "25.pdf"

Hello Adam & Stefan,

Thank you both for helping. The problem is that there is no logic in the numbering (perhaps due the fact that I’m not Rainman :wink: )

What I want to do is to make a automator worklflow for a new Dutch Newspaper called De Pers the sameway I did for the Metro Newspaper ( http://automatoractions.com/files/metroworkflow1.9.html )

see the weird numbering from the newspaper website;

http://www.depers.nl/uitgaven.php

Think gonna write the newspaper to kindly ask them if they can change the naming into something workable… you never know perhaps they listen… never hapens when you do not ask it or not?

Keep you informed :slight_smile:

Have a nice day!

Bob

Hi Bob,

try this, it should work on condition, that the design of the website doesn’t change
It grabs the date of the topmost issue and the corresponding URL from the site , compares it with
the current date and download the pdf, if the dates match.
(I hope, the dutch month names are correct ;))

property destinationfolder : path to desktop as Unicode text
property monthList : {"januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"}

tell (current date) to set {dy, mn, yr} to {day, its month as integer, year}
-- get date of topmost issue
set currentIssue to words 4 thru 6 of (do shell script "curl http://www.depers.nl/uitgaven.php | grep 'Uitgave van'")
-- compare current date with date of current issue
if item 1 of currentIssue as integer = dy and item 2 of currentIssue = item mn of monthList and item 3 of currentIssue as integer = yr then
	set theURL to paragraph 1 of (do shell script "curl http://www.depers.nl/uitgaven.php | grep lees | cut -f 2 -d '\"' | cut -f 1 -d '\"'")
	set datestring to ((dy as string) & "_" & mn as string) & "_" & yr as string
	set destpath to quoted form of POSIX path of (destinationfolder & "DagbladDePers-" & datestring & ".pdf")
	do shell script "curl " & theURL & " -o " & destpath
end if

wow stefan many thanks that does the trick! When running the script the newspaper is downloaded perfectly.

one little question more as “brutal” me is :wink:

After I Placed the script within Automator and so it places the lastest issue on the desktop, I cannot simply use the “open images in preview”. So have to ad something extra I guess within the script? Do you have a clue?

Thanks

Bob

ps will send you also a e-mail soon with some aditional info/ question

Hi Bob,

I would just add a line to open the downloaded pdf in preview.app

...
	set datestring to ((dy as string) & "_" & mn as string) & "_" & yr as string
	set currentIssueFile to destinationfolder & "DagbladDePers-" & datestring & ".pdf"
	do shell script "curl " & theURL & " -o " & quoted form of POSIX path of currentIssueFile
	tell application "Preview" to open currentIssueFile
end if

Hello Stefan,

tested it and works like a charm :slight_smile:

(again) thanks

Bob