Jump to content

auto download


 Share

Go to solution Solved by GMK,

Recommended Posts

Hi all :)

I'm trying to make a script that automatically downloads issues of my favourite free comic book

Here is the code:

#include <Inet.au3>
#include <File.au3>
If UBound(ProcessList(@ScriptName)) > 2 Then
MsgBox(4096, "Error", @ScriptName&" is already running.", 5)
Exit
EndIf
Global $main = 'site url'
Global $file = @ScriptDir&'\log.txt'

If FileExists($file)=0 Then
FileWrite($file,'First run: '&@YEAR&' '&@MON&@CRLF)
TrayTip('No log file found','Assuming this is the first run. Donwloading of all content starting...',30)
_getall()
Else
If FileReadLine($file,-1) <> 'Last run '&@YEAR&' '&@MON Then _checknew()
EndIf
Exit
Func _download($year,$month)

TrayTip('Downloading',$main&$year&'/'&StringFormat('%02d',$month),30)

$source = StringSplit(_INetGetSource($main&$year&'/'&StringFormat('%02d',$month)),'"')

If @error then
FileWriteLine($file,'---'&@CRLF&'Not found '&$year&' '&StringFormat('%02d',$month))
SetError(0)
Return 0
EndIf

For $n= 1 to $source[0]
If StringInStr($source[$n],'.pdf') then InetGet($main&$year&'/'&StringFormat('%02d',$month)&'/'&$source[$n],@ScriptDir&'\'&$year&'\'&StringFormat('%02d',$month)&'\'&$n&'.pdf')
If @error then
MsgBox(16,'ERROR','Download error at '&@CRLF&$main&$year&'/'&StringFormat('%02d',$month)&'/'&$source[$n])
FileWriteLine($file,'---'&@CRLF&'Download error at '&$main&$year&'/'&StringFormat('%02d',$month)&'/'&$source[$n])
SetError(0)
Return 0
EndIf
Next

FileWriteLine($file,'---'&@CRLF&'Success'&$year&' '&StringFormat('%02d',$month))

EndFunc
Func _getall()
For $i='2012' to @YEAR
For $j='01' to '12'
_download($i,$j)
Next
Next

FileWriteLine($file,'---'&@CRLF&'Last run '&@YEAR&' '&@MON)

EndFunc
Func _checknew()

TrayTip('Checking...','',30)
_download (@YEAR,@MON)

EndFunc

The problem is that even if i can retrieve the right link i always get download error.

Any other suggestions welcome.

Regards and sorry for my 'newbieness'.

Edited by zentral
Link to comment
Share on other sites

What exactly is this line supposed to be doing?

StringSplit(_INetGetSource($main & $year & '/' & StringFormat('%02d', $month)), '"')

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ahem.

As i don't know how to read links from a webpage i figured out to get the source, split it and get the links from here.

So this gets the source of the desired webpage.

Edited by zentral
Link to comment
Share on other sites

What that line does is, it gets the source of the site, and splits it on any double quotes it finds in the text returned. Is that what you're intending for it to do? Have you checked the contents of the array after that has been run to see if it contains what you want it to contain?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Look at the _IE functions for finding the links, someone more knowledgeable than me would have to help you with that because I almost never use them.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Solution

Quick example:

#include <IE.au3>
#include <Array.au3>
Local $avLinks
Local $sURL = "http://www.irs.gov/uac/Forms,-Publications,-and-Other-Tax-Products"
Local $oIE = _IECreate($sURL)
Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    If StringRight($oLink.href, 4) = ".pdf" Then
        If Not IsArray($avLinks) Then
            Local $avLinks[2] = [1, $oLink.href]
        Else
            ReDim $avLinks[UBound($avLinks) + 1]
            $avLinks[0] += 1
            $avLinks[UBound($avLinks) - 1] = $oLink.href
        EndIf
    EndIf
Next
_ArrayDisplay($avLinks)
;Then you can loop through the array and use InetGet to download the files

Edited by GMK
Link to comment
Share on other sites

For $j= 1 to $avLinks[0]
   TrayTip('Downloading',$avLinks[$j]&' to'& $ddir&$j&StringRight($avLinks[$j], 4),30)
   InetGet($avLinks[$j],$ddir&$j&StringRight($avLinks[$j], 4))
Next
TrayTip('Done','',30)

This way? :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...