Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting several files from Web
#1
Hi,

Recently, I learned here how to get a file from internet and rename it with the current data in my PC.

I'm using the follow link:

Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1) end "The thread is already running. You can end it in the 'Running items' pane."

str sf sd ;;variables

;download image data into variable sd
int downloaded
rep 60 ;;repeat max 10 minutes every 10 s until success
,IntGetFile "http://image.weather.com/images/maps/forecast/precfcst_600x405.jpg" sd
,err 10; continue ;;if error, retry after 10 s
,downloaded=1
,break
if(!downloaded) end "failed to download"

;format filename and save to file
sf.timeformat("$my qm$\Image-{yyyy-MM-dd}.jpg")
sd.setfile(sf)

run sf ;;open the image. Delete this line if don't need.



However, now I'm trying to do the same macro for 87 links...and it's getting very tiring, because i have to make 87 macros.


So, How can i make it in a single macro ? I mean...I'd like to list all the links in the same macro.


Again, thanks a lot for helping.
#2
Macro Macro20
Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1) end "The thread is already running. You can end it in the 'Running items' pane."

;Add up to 87 links as you like.
str s=
;link 1
;link 2
;link 3

str line sf sd ;;variables
foreach line s
,rep 60
,,IntGetFile line
,,err 10; continue ;;if error, retry after 10 s
,,downloaded=1
,,break
,if(!downloaded) end "failed to download"

;format filename and save to file
,sf.timeformat("$my qm$\Image-{yyyy-MM-dd}.jpg")
,sd.setfile(sf)
#3
similar, with a sub-function

Macro Macro2472
Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1) end "The thread is already running. You can end it in the 'Running items' pane."
;create folder for files
str folder="$desktop$\test643"
mkdir folder

;list of files to download
str files=
;http://www.quickmacros.com/download.html
;http://www.quickmacros.com/support.html

;call sub-function Download for each file
str s
foreach s files
,sub.Download folder s


#sub Download
function str'folder str'url
spe -1

str sf sd ;;variables

;download imagefile data into variable sd
int downloaded
rep 60 ;;repeat max 10 minutes every 10 s until success
,IntGetFile url sd
,err 10; continue ;;if error, retry after 10 s
,downloaded=1
,break
if(!downloaded) end F"failed to download {url}"

;format filename and save to file
sf.getfilename(url 1)
sd.setfile(F"{folder}\{sf}")
#4
Guys,

It worked...thank you.

I just have one issue...

I'd like to rename the file, inserting the current date, but keeping the same extension.

I tried:
Code:
Copy      Help
sf.getfilename(url 1)
sf.timeformat("File1-{yyyy-MM-dd}")
sd.setfile(F"{folder}\{sf}")

But it failed

Could you please help me once more?
#5
Macro Macro20
Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1) end "The thread is already running. You can end it in the 'Running items' pane."
;create folder for files
str folder="$desktop$\test643"
mkdir folder

;Add up to 87 links as you like.
str s=
;http://www.quickmacros.com/download.html
;http://www.quickmacros.com/support.html

int downloaded index=1
str line sf sd timef;;variables
foreach line s
,rep 60
,,IntGetFile line sd
,,err 10; continue ;;if error, retry after 10 s
,,downloaded=1
,,break
,if(!downloaded) end "failed to download"

,;format filename and save to file
,timef.timeformat("{yyyy-MM-dd}")
,_s.from(folder "\" "File" index "-" timef)
,sd.setfile(_s)
,index+1
#6
Lionking,

It's almost there. But the macro is saving with no extension.

Do you know how can I fix it ?

Another point, I saw you put "Index" to create File1, File2, File3...This is very useful for me...but in some files (I can run in another macro) I'd like to keep the original name of the file.

Ex1:
http://www.eduplace.com/ss/maps/pdf/us_nl.pdf
The Macro will save as: us_nl 2014-12-26.pdf

Ex2:
http://www.un.org/Depts/dhl/maplib/imag ... unflag.gif
The Macro will save as: unflag 2014-12-26.gif

Sorry for the long post, but I really appreciate your help.
#7
Macro Macro26
Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1) end "The thread is already running. You can end it in the 'Running items' pane."
;create folder for files
str folder="$desktop$\test643"
mkdir folder

;list of files to download
str files=
;http://www.eduplace.com/ss/maps/pdf/us_nl.pdf
;http://www.un.org/Depts/dhl/maplib/images_maplib/unflag.gif

;call sub-function Download for each file
str s
int filenum=1
foreach s files
,sub.Download folder s filenum
,filenum+1


#sub Download
function str'folder str'url index
spe -1

str sf sd ;;variables

;download imagefile data into variable sd
int downloaded
rep 60 ;;repeat max 10 minutes every 10 s until success
,IntGetFile url sd
,err 10; continue ;;if error, retry after 10 s
,downloaded=1
,break
if(!downloaded) end F"failed to download {url}"

;format filename and save to file
sf.getfilename(url 1)
str ext.GetFilenameExt(sf)
str timef.timeformat("{yyyy-MM-dd}")
_s.from("File" index "-" timef "." ext)
sd.setfile(F"{folder}\{_s}")
#8
This is Perfect!

Thanks a lot, Lionking. :mrgreen:


Forum Jump:


Users browsing this thread: 1 Guest(s)