Advertisement
Guest User

ElektorMagazine.ps1

a guest
Oct 9th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Fonction Selectioner un dossier de destination
  2. function SelectFolder {
  3.     $object = New-Object -comObject Shell.Application
  4.     $folder = $object.BrowseForFolder(0, "Sélectionnez un dossier de destination", 0, 0)
  5.         $folder.self.Path
  6. }
  7.  
  8. #Fonction : Télécharger les magazines de 2013 à aujourd'hui
  9. function fun2013-Now($year) {
  10.     mkdir $folder\ElektorMagazine\$year | Out-Null
  11.     #Année en cours
  12.     if ($year -eq $yearNow) {
  13.         #Pas de magazine au mois de février et aout
  14.         for ($month=1; $month -le $monthNowInt; $month++){
  15.             if ($month -ne 2 -and $month -ne 8){
  16.                 $month00 = "{0:D2}" -f $month
  17.                 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
  18.             }
  19.         }
  20.     }
  21.     else {
  22.         #Pas de magazine au mois de février et aout
  23.         for ($month=1; $month -le 12; $month++){
  24.             if ($month -ne 2 -and $month -ne 8){
  25.                 $month00 = "{0:D2}" -f $month
  26.                 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
  27.             }
  28.         }
  29.     }
  30. }
  31.  
  32. #Fonction : Télécharger les magazines de 2000 à 2012
  33. function fun1990-2012($year) {
  34.     mkdir $folder\ElektorMagazine\$year | Out-Null
  35.     #Pas de magazine au mois d'aout
  36.     for ($month=1; $month -le 12; $month++){
  37.         if ($month -ne 8){
  38.             $month00 = "{0:D2}" -f $month
  39.             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
  40.         }
  41.     }
  42. }
  43.  
  44. #Fonction : Télécharger tous les magazines (1990 à aujourd'hui)
  45. function funAllYears {
  46.     for ($year=1990; $year -le 2012; $year++){
  47.         fun1990-2012($year)
  48.     }
  49.     for ($year=2013; $year -le $yearNowInt; $year++){
  50.         fun2013-Now($year)
  51.     }
  52. }
  53.  
  54. $yearNow = Get-Date -UFormat "%Y"
  55. $yearNowInt =[convert]::ToInt32($yearNow, 10)
  56. $monthNow = Get-Date -UFormat "%m"
  57. $monthNowInt =[convert]::ToInt32($monthNow, 10)
  58.  
  59. echo "Télécharger tout ou partie des magazines Elektor"
  60. echo "Nécéssite un abonnement GREEN ou GOLD"
  61. $elektorEmail = Read-Host -Prompt "Email"
  62. $elektorPassword = Read-Host -AsSecureString -Prompt "Mot de passe"
  63. $elektorPassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($elektorPassword))
  64. $dateWant = Read-Host -Prompt "Année voulue [Toutes]"
  65. $folder = SelectFolder
  66.  
  67. mkdir $folder\ElektorMagazine  | Out-Null
  68. $postAuth = @{username=$elektorEmail;password=$elektorPassword;remember='1'}
  69. $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"}
  70. Invoke-WebRequest -Uri https://www.elektormagazine.fr/account/login -Method POST -Body $postAuth -SessionVariable elektorSession -Headers $headers | Out-Null
  71.  
  72. if ($dateWant -ge 2013 -and $dateWant -le $yearNow) {$case = 1}
  73. elseif ($dateWant -ge 1990 -and $dateWant -le 2012) {$case = 2}
  74. else {$case = 3}
  75. switch ($case)
  76.     {
  77.         1 {fun2013-Now($dateWant)}
  78.         2 {fun1990-2012($dateWant)}
  79.         3 {funAllYears}
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement