From fa485cde43f7f67b3d5f873028c59ce295f52579 Mon Sep 17 00:00:00 2001 From: Lifailon Date: Wed, 8 May 2024 21:44:23 +0300 Subject: [PATCH] added json file generation with free games --- .github/workflows/main.yml | 16 ++++------------ Scripts/FreeGamesList.ps1 | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b5dd35b..8784845 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,9 @@ name: Publish Free Games List on: - workflow_dispatch: # Разрешить ручной запуск + workflow_dispatch: # Разрешить ручной запуск # schedule: -# - cron: '* 1 * * *' # Запускать каждый 1 час +# - cron: '* 1 * * *' # Запускать каждый 1 час jobs: fetch_and_publish: @@ -13,14 +13,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 -# - name: Setup PowerShell -# uses: actions/setup-powershell@v1 -# with: -# pwsh-version: '7.3.7' - -# - name: Run PowerShell script -# run: .\Scripts\FreeGamesList.ps1 - - name: Run PowerShell script run: pwsh -File ./Scripts/FreeGamesList.ps1 shell: bash @@ -30,5 +22,5 @@ jobs: git config --global user.name 'GitHub Actions' git config --global user.email 'actions@github.com' git add . - git commit -m "Update free games list" - git push + git commit -m "Update free games list" || echo "No changes to commit" + git push || echo "No changes to push" \ No newline at end of file diff --git a/Scripts/FreeGamesList.ps1 b/Scripts/FreeGamesList.ps1 index f8ec309..44c3267 100644 --- a/Scripts/FreeGamesList.ps1 +++ b/Scripts/FreeGamesList.ps1 @@ -1,12 +1,17 @@ $count = "500" $price = "tierFree" $url = "https://store.epicgames.com/ru/browse?sortBy=releaseDate&sortDir=DESC&priceTier=$($price)&category=Game&count=$($count)&start=0" -$headers = @{ - "User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" - "Accept" = "text/html" -} -$response = Invoke-WebRequest -Uri $url -Headers $headers -Method Get -$json = $($($($response.Content -split "__REACT_QUERY_INITIAL_QUERIES__ = ")[1] -split "window.server_rendered")[0] -replace ";") + +$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 +$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 + +$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 = "$PWD\freeGames.json" -$games | Out-File $path \ No newline at end of file + +$path = "${env:GITHUB_WORKSPACE}/freeGames.json" +$games | ConvertTo-Json -Depth 10 | Out-File $path \ No newline at end of file