Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Fonction Selectioner un dossier de destination
- function SelectFolder {
- $object = New-Object -comObject Shell.Application
- $folder = $object.BrowseForFolder(0, "Sélectionnez un dossier de destination", 0, 0)
- $folder.self.Path
- }
- #Fonction : Télécharger les magazines de 2013 à aujourd'hui
- function fun2013-Now($year) {
- mkdir $folder\ElektorMagazine\$year | Out-Null
- #Année en cours
- if ($year -eq $yearNow) {
- #Pas de magazine au mois de février et aout
- for ($month=1; $month -le $monthNowInt; $month++){
- if ($month -ne 2 -and $month -ne 8){
- $month00 = "{0:D2}" -f $month
- Invoke-WebRequest -Uri https://www.elektormagazine.fr/files/magazine/$year/magazine/FR$year$month00.pdf -OutFile $folder\ElektorMagazine\$year\FR$year$month00.pdf -WebSession $elektorSession | Out-Null
- }
- }
- }
- else {
- #Pas de magazine au mois de février et aout
- for ($month=1; $month -le 12; $month++){
- if ($month -ne 2 -and $month -ne 8){
- $month00 = "{0:D2}" -f $month
- Invoke-WebRequest -Uri https://www.elektormagazine.fr/files/magazine/$year/magazine/FR$year$month00.pdf -OutFile $folder\ElektorMagazine\$year\FR$year$month00.pdf -WebSession $elektorSession | Out-Null
- }
- }
- }
- }
- #Fonction : Télécharger les magazines de 2000 à 2012
- function fun1990-2012($year) {
- mkdir $folder\ElektorMagazine\$year | Out-Null
- #Pas de magazine au mois d'aout
- for ($month=1; $month -le 12; $month++){
- if ($month -ne 8){
- $month00 = "{0:D2}" -f $month
- Invoke-WebRequest -Uri https://www.elektormagazine.fr/files/magazine/$year/magazine/FR$year$month00.pdf -OutFile $folder\ElektorMagazine\$year\FR$year$month00.pdf -WebSession $elektorSession | Out-Null
- }
- }
- }
- #Fonction : Télécharger tous les magazines (1990 à aujourd'hui)
- function funAllYears {
- for ($year=1990; $year -le 2012; $year++){
- fun1990-2012($year)
- }
- for ($year=2013; $year -le $yearNowInt; $year++){
- fun2013-Now($year)
- }
- }
- $yearNow = Get-Date -UFormat "%Y"
- $yearNowInt =[convert]::ToInt32($yearNow, 10)
- $monthNow = Get-Date -UFormat "%m"
- $monthNowInt =[convert]::ToInt32($monthNow, 10)
- echo "Télécharger tout ou partie des magazines Elektor"
- echo "Nécéssite un abonnement GREEN ou GOLD"
- $elektorEmail = Read-Host -Prompt "Email"
- $elektorPassword = Read-Host -AsSecureString -Prompt "Mot de passe"
- $elektorPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($elektorPassword))
- $dateWant = Read-Host -Prompt "Année voulue [Toutes]"
- $folder = SelectFolder
- mkdir $folder\ElektorMagazine | Out-Null
- $postAuth = @{username=$elektorEmail;password=$elektorPassword;remember='1'}
- $headers = @{"Origin"="Origin: https://www.elektormagazine.fr";"referer"="https://www.elektormagazine.fr/account/mssc/login";"User-Agent"="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"}
- Invoke-WebRequest -Uri https://www.elektormagazine.fr/account/login -Method POST -Body $postAuth -SessionVariable elektorSession -Headers $headers | Out-Null
- if ($dateWant -ge 2013 -and $dateWant -le $yearNow) {$case = 1}
- elseif ($dateWant -ge 1990 -and $dateWant -le 2012) {$case = 2}
- else {$case = 3}
- switch ($case)
- {
- 1 {fun2013-Now($dateWant)}
- 2 {fun1990-2012($dateWant)}
- 3 {funAllYears}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement