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 9659549 commit fa485cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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"
21 changes: 13 additions & 8 deletions Scripts/FreeGamesList.ps1
Original file line number Diff line number Diff line change
@@ -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

$path = "${env:GITHUB_WORKSPACE}/freeGames.json"
$games | ConvertTo-Json -Depth 10 | Out-File $path

0 comments on commit fa485cd

Please sign in to comment.