Skip to content

Commit

Permalink
added json file generation with free games
Browse files Browse the repository at this point in the history
  • Loading branch information
Lifailon committed May 8, 2024
1 parent 6f2bd2f commit 801e0f0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Scripts/FreeGamesList.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Переменные url
$count = "500"
$price = "tierFree"
$url = "https://store.epicgames.com/ru/browse?sortBy=releaseDate&sortDir=DESC&priceTier=$($price)&category=Game&count=$($count)&start=0"

# Делаем запрос
$userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
$httpClient = New-Object System.Net.Http.HttpClient
$handler = New-Object System.Net.Http.HttpClientHandler
$handler.AllowAutoRedirect = $true
$httpClient = New-Object System.Net.Http.HttpClient($handler)
$requestMessage = [System.Net.Http.HttpRequestMessage]::new([System.Net.Http.HttpMethod]::Get, $url)
$requestMessage.Headers.Add("User-Agent", $userAgent)
$requestMessage.Headers.Add("Accept", "text/html")
$response = $httpClient.SendAsync($requestMessage).Result
$content = $response.Content.ReadAsStringAsync().Result

Write-Host "---------------------- Start JSON ----------------------"
# Логируем (проверяем содержимое)
Write-Host "---------------------- Content ----------------------"
Write-Host $content
Write-Host "---------------------- End JSON ------------------------"

Write-Host "---------------------- Content ------------------------"
# Вытаскиваем json из html
$json = $($($($content -split "__REACT_QUERY_INITIAL_QUERIES__ = ")[1] -split "window.server_rendered")[0] -replace ";")
# Обрабатываем данные
$games = $($json | ConvertFrom-Json).queries.state.data[-1].catalog.searchStore.elements

# Сохраняем файл
$path = "${env:GITHUB_WORKSPACE}/freeGames.json"
$games | ConvertTo-Json -Depth 10 | Out-File $path

0 comments on commit 801e0f0

Please sign in to comment.