Advertisement
sarumeister

Untitled

Jul 13th, 2025
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # run as
  2. # powershell -ExecutionPolicy Bypass -File "currency_data.ps1"
  3.  
  4. # Get current date
  5. $currentDate = Get-Date
  6. $endDay = $currentDate.ToString("dd")
  7. $endMonth = $currentDate.ToString("MM")
  8. $endYear = $currentDate.ToString("yyyy")
  9.  
  10. # Calculate date 10 days ago for beginning date
  11. $beginDate = $currentDate.AddDays(-40)
  12. $begDay = $beginDate.ToString("dd")
  13. $begMonth = $beginDate.ToString("MM")
  14. $begYear = $beginDate.ToString("yyyy")
  15.  
  16. # Form the GET strings
  17. $url1 = "https://nbkr.kg/index1.jsp?item=1562&lang=RUS&valuta_id=20&beg_day=$begDay&beg_month=$begMonth&beg_year=$begYear&end_day=$endDay&end_month=$endMonth&end_year=$endYear"
  18. $url2 = "https://nbkr.kg/index1.jsp?item=1562&lang=RUS&valuta_id=44&beg_day=$begDay&beg_month=$begMonth&beg_year=$begYear&end_day=$endDay&end_month=$endMonth&end_year=$endYear"
  19.  
  20. Write-Host "Fetching data from first URL: $url1"
  21.  
  22. try {
  23.     # Fetch the first HTML content
  24.     $response1 = Invoke-WebRequest -Uri $url1 -UseBasicParsing
  25.     $htmlContent1 = $response1.Content
  26.    
  27.     # Find the lineChartData variable using regex
  28.     $pattern = 'var lineChartData = \{[^}]+labels\s*:\s*\[([^\]]+)\][^}]+data\s*:\s*\[([^\]]+)\]'
  29.    
  30.     if ($htmlContent1 -match $pattern) {
  31.         $labelsString = $matches[1]
  32.         $dataOneString = $matches[2]
  33.        
  34.         # Clean up and parse labels (remove quotes and whitespace)
  35.         $labels = $labelsString -split ',' | ForEach-Object { $_.Trim().Trim('"') }
  36.        
  37.         # Clean up and parse first data (remove whitespace)
  38.         $dataOne = $dataOneString -split ',' | ForEach-Object { $_.Trim() }
  39.        
  40.         Write-Host "Fetching data from second URL: $url2"
  41.        
  42.         # Fetch the second HTML content
  43.         $response2 = Invoke-WebRequest -Uri $url2 -UseBasicParsing
  44.         $htmlContent2 = $response2.Content
  45.        
  46.         if ($htmlContent2 -match $pattern) {
  47.             $dataTwoString = $matches[2]
  48.            
  49.             # Clean up and parse second data (remove whitespace)
  50.             $dataTwo = $dataTwoString -split ',' | ForEach-Object { $_.Trim() }
  51.            
  52.             Write-Host "`nExtracted Data:"
  53.             Write-Host "==============="
  54.            
  55.             # Output label-data pairs
  56.             for ($i = 0; $i -lt $labels.Length -and $i -lt $dataOne.Length -and $i -lt $dataTwo.Length; $i++) {
  57.                 Write-Host "$($labels[$i]) - $($dataOne[$i]) - $($dataTwo[$i])"
  58.             }
  59.            
  60.             # Save to file
  61.             $outputFile = "currency_data.txt"
  62.             $output = @()
  63.             for ($i = 0; $i -lt $labels.Length -and $i -lt $dataOne.Length -and $i -lt $dataTwo.Length; $i++) {
  64.                 $output += "$($labels[$i]) - $($dataOne[$i]) - $($dataTwo[$i])"
  65.             }
  66.             $output | Out-File -FilePath $outputFile -Encoding UTF8
  67.            
  68.             Write-Host "`nData saved to: $outputFile"
  69.            
  70.             # Open the file in notepad
  71.             Start-Process "notepad.exe" -ArgumentList $outputFile
  72.            
  73.         } else {
  74.             Write-Host "Could not find lineChartData in the second HTML response"
  75.         }
  76.        
  77.     } else {
  78.         Write-Host "Could not find lineChartData in the first HTML response"
  79.         Write-Host "Response preview:"
  80.         Write-Host $htmlContent1.Substring(0, [Math]::Min(500, $htmlContent1.Length))
  81.     }
  82.    
  83. } catch {
  84.     Write-Host "Error fetching data: $($_.Exception.Message)"
  85. }
  86.  
Tags: currency nbkr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement