-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_report.ps1
40 lines (33 loc) · 1.28 KB
/
pdf_report.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#TODO, improve id incrementing (not including weekends & holidays)
$counter = 0;
#minimum 3219 (December 1 2016)
#December 1 2016 to September 30 2020, $counter == 930
$starting_id = 4243 #February 15 2021
$year = 2021
$last_id = 4261 #March 12 2021
$id_border = 3239, 3482, 3727, 3971, 4213
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
for ($id = $starting_id; $id -le $last_id; $id++) {
if ($id -in $id_border) {
++$year
}
$url = "https://www.pse.com.ph" `
+"/stockMarket/marketInfo-marketActivity-marketReports.html" `
+"?ajax=true&method=downloadMarketReports&ids=[%22PSE_DQTRT$year$id%22]"
$response = Invoke-WebRequest `
-Uri "$url" `
-Headers @{
'Referer'= 'https://www.pse.com.ph/stockMarket/marketInfo-marketActivity.html?tab=4';
} `
-Method Get
try {
$file_name = [System.Net.Mime.ContentDisposition]::new($response.Headers['Content-Disposition']).FileName
[System.IO.File]::WriteAllBytes("$PSScriptRoot\pdf\$file_name", $response.Content)
}
catch [System.IndexOutOfRangeException], [System.Management.Automation.MethodException] {
continue
}
Write-Host "$file_name saved ($year$id)"
++$counter
}
Write-Host "$counter total saves"