Downloading pdfs
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Downloading pdfs
I used to be a LiveCode developer but I've been away from the platform for a few years.
I have 524 pdf files on a web server, at http://webserver.com/1 to http://webserver.com/524. I want a script that will download them all to a folder on my desktop (one at a time is fine, and it doesn't have to be quick).
Can someone suggest a strategy for doing that?
Cheers
Gerry
I have 524 pdf files on a web server, at http://webserver.com/1 to http://webserver.com/524. I want a script that will download them all to a folder on my desktop (one at a time is fine, and it doesn't have to be quick).
Can someone suggest a strategy for doing that?
Cheers
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.
Re: Downloading pdfs
HI Gerry,
welcome back!
Use a simple repeat loop:
Of course some errorchecking (if the result <> emtpy then...) after each "put" will not hurt!
Best
Klaus
welcome back!
Use a simple repeat loop:
Code: Select all
...
put specialfolderpath("desktop") & "/" into tTargetFolder
put "http://webserver.com/" into tSourceFolder
repeat with i = 1 to 524
put url(tSourceFolder & i) into url("binfile:" & tTargetfolder & i & ".pdf")
## Give engine some time to "breathe":
wait 1 with messages
end repeat
...
Best
Klaus
Re: Downloading pdfs
Thanks, but it's not for long
And thanks for your help. It's amazing what you forget in such a short time
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.
Re: Downloading pdfs
Ok, seems the server is funky in the way it's handling the pdfs. When you go to https://websever.com/1 or https://websever.com/1.pdf in a browser, a pdf loads. But when I run your code, it creates an empty pdf. The error I get when I try to open it in Preview is "The file “2.pdf” could not be opened because it is empty."
Oh well
Cheers
Gerry
Oh well
Cheers
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.
Re: Downloading pdfs
Hi again
I tried again with a known, valid .pdf. The following returns "can't open file":
Sigh.
Gerry
I tried again with a known, valid .pdf. The following returns "can't open file":
Code: Select all
put specialfolderpath("desktop") & "/" into tTargetFolder
put "http://www.africau.edu/images/default/sample.pdf" into tSourceFolder
put url(tSourceFolder) into url("binfile:" & tTargetfolder)
answer the result
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.
Re: Downloading pdfs
Try this method:
Using libUrlDownloadToFile give you a call back message for the download status which really helps to tie down what is happening.
Also note that the name of the file and not just the location to save to MUST be specified.
Code: Select all
on mouseUp pMouseButton
put specialfolderpath("desktop") & "/" into tTargetFolder
put "http://www.africau.edu/images/default/sample.pdf" into tSourceFolder
libUrlDownloadToFile tSourceFolder, tTargetFolder & "sample.pdf", "downloadEnd"
end mouseUp
on downloadEnd tSourceFolder, pStatus
if pStatus is not "downloaded" then
answer "Download failed"
end if
unload url tSourceFolder
end downloadEnd
Also note that the name of the file and not just the location to save to MUST be specified.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Downloading pdfs
A variation on the previous method
This will automatically retrieve the the file name of the source and add it to the target file location
Code: Select all
on mouseUp pMouseButton
set the itemdel to "/" --new
put specialfolderpath("desktop") & "/" into tTargetFolder
put "http://www.africau.edu/images/default/sample.pdf" into tSourceFolder
put item -1 of tSourceFolder into tFileName --new
libUrlDownloadToFile tSourceFolder, tTargetFolder & tFileName, "downloadEnd" --amended
end mouseUp
on downloadEnd tSourceFolder, pStatus
if pStatus is not "downloaded" then
answer "Download failed"
end if
unload url tSourceFolder
end downloadEnd
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Downloading pdfs
This worked fine for me:
IT and THE RESULT were both empty.
I suspect some HTML "tricks", like redirect or whatever, involved in the URLs -> http://webserver.com/1
since that is obviously NOT the "direct" url to the PDF.
I can see the same on the LC webpage for Datagrid lessons: http://lessons.livecode.com/m/datagrid
There you can download the PDF with this link: http://lessons.livecode.com/m/datagrid/pdf
The tiny (must be 2 point textsize ) link below the topics on the left side.
However:
put url("http://lessons.livecode.com/m/datagrid/pdf") into ttt
Give an EMPTY variable ttt?
Sorry, no ideas so far...
Code: Select all
on mouseUp
put specialfolderpath("desktop") & "/sample.pdf" into tTargetFolder
put "http://www.africau.edu/images/default/sample.pdf" into tSourceFolder
put url(tSourceFolder) into url("binfile:" & tTargetfolder)
answer IT & CR & the result
end mouseUp
I suspect some HTML "tricks", like redirect or whatever, involved in the URLs -> http://webserver.com/1
since that is obviously NOT the "direct" url to the PDF.
I can see the same on the LC webpage for Datagrid lessons: http://lessons.livecode.com/m/datagrid
There you can download the PDF with this link: http://lessons.livecode.com/m/datagrid/pdf
The tiny (must be 2 point textsize ) link below the topics on the left side.
However:
put url("http://lessons.livecode.com/m/datagrid/pdf") into ttt
Give an EMPTY variable ttt?
Sorry, no ideas so far...
Re: Downloading pdfs
Your script worked perfectly! This forum saved my bacon years ago, and again today
Thanks Andy, Klaus!
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.
Former LiveCode developer.
Now recovering.