From 210ec9adb7f80325fe16c7679a60134938213edb Mon Sep 17 00:00:00 2001 From: Lifailon Date: Sat, 11 May 2024 03:53:46 +0300 Subject: [PATCH] update module --- .github/workflows/main.yml | 9 +-- README.md | 2 +- json/FreeGames.json => api/free/index.json | 0 module/Get-GameList.ps1 | 65 ++++++++++++++++++++++ scripts/FreeGamesList.ps1 | 58 ------------------- 5 files changed, 69 insertions(+), 65 deletions(-) rename json/FreeGames.json => api/free/index.json (100%) create mode 100644 module/Get-GameList.ps1 delete mode 100644 scripts/FreeGamesList.ps1 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c9a1661..adc9cd2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,25 +1,22 @@ name: build-free-games-list on: - workflow_dispatch: # Разрешить ручной запуск + workflow_dispatch: # schedule: -# - cron: '* 1 * * *' # Запускать каждый 1 час +# - cron: '00 00 * * *' jobs: Job_01: runs-on: ubuntu-latest steps: - # Загружаем репозиторий - name: Checkout repository uses: actions/checkout@v2 - # Выполняем скрипт - name: Get content and write to file - run: pwsh -File ./scripts/FreeGamesList.ps1 + run: pwsh -File ./module/Get-GameList.ps1 shell: bash - # Выгружаем файл в репозиторий - name: Commit and push changes run: | git config --global user.name 'GitHub Actions' diff --git a/README.md b/README.md index 4249de3..6a1edcf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# EpicGames Statistics +# Epic Games Stats Данный рипозиторий содержит списки игр, который ежедневно обновляется с помощью GitHub Actions. diff --git a/json/FreeGames.json b/api/free/index.json similarity index 100% rename from json/FreeGames.json rename to api/free/index.json diff --git a/module/Get-GameList.ps1 b/module/Get-GameList.ps1 new file mode 100644 index 0000000..1f1678a --- /dev/null +++ b/module/Get-GameList.ps1 @@ -0,0 +1,65 @@ +$price = "tierDiscouted" # tierFree +$region = "ru" # en-US +$count = "500" +$url = "https://store.epicgames.com/$region/browse?sortBy=releaseDate&sortDir=DESC&priceTier=$($price)&category=Game&count=$($count)&start=0" +$Agents = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" + +# v1 (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 + +# v2 (WebClient) +# $WebClient = New-Object System.Net.WebClient +# $userAgent = Get-Random -InputObject $Agents +# $WebClient.Headers.Add("User-Agent", $userAgent) +# $WebClient.Headers.Add("Accept", "text/html") +# $content = $WebClient.DownloadString($url) + +# v3 (2nd query from trace in browser) +$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession +$session.UserAgent = $Agents +$response = Invoke-WebRequest -Uri $url -WebSession $session -Headers @{ + "Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" + "Service-Worker-Navigation-Preload"="true" + "Upgrade-Insecure-Requests"="1" + "sec-ch-ua"="`"Chromium`";v=`"124`", `"Google Chrome`";v=`"124`", `"Not-A.Brand`";v=`"99`"" + "sec-ch-ua-mobile"="?0" + "sec-ch-ua-platform"="`"Windows`"" +} +$content = $response.Content + +Write-Host "---------------------- Content ----------------------" +Write-Host $content +Write-Host "---------------------- Content ------------------------" + +# Get json from html +$json = $($($($content -split "__REACT_QUERY_INITIAL_QUERIES__ = ")[1] -split "window.server_rendered")[0] -replace ";") + +# Data filtering +$games = $($json | ConvertFrom-Json).queries.state.data[-1].catalog.searchStore.elements + +# Output formatting +$Collections = New-Object System.Collections.Generic.List[System.Object] +foreach ($game in $games) { + $Collections.Add([PSCustomObject]@{ + Title = $game.title + Developer = $game.developerDisplayName + publisher = $game.publisherDisplayName + Description = $game.description + Url = "https://store.epicgames.com/$region/p/$($game.offerMappings.pageSlug)" + ReleaseDate = $game.releaseDate + FullPrice = $game.price.totalPrice.fmtPrice.originalPrice + Discount = "$(1-$($game.price.totalPrice.discountPrice)/$($game.price.totalPrice.originalPrice)*100) %" + CurrentPrice = $game.price.totalPrice.fmtPrice.discountPrice + }) +} + +# Save file +$path = "${env:GITHUB_WORKSPACE}/api/free/index.json" +$Collections | ConvertTo-Json -Depth 10 | Out-File $path \ No newline at end of file diff --git a/scripts/FreeGamesList.ps1 b/scripts/FreeGamesList.ps1 deleted file mode 100644 index 3e82d37..0000000 --- a/scripts/FreeGamesList.ps1 +++ /dev/null @@ -1,58 +0,0 @@ -# Переменные url -$count = "500" -$price = "tierFree" -$url = "https://store.epicgames.com/ru/browse?sortBy=releaseDate&sortDir=DESC&priceTier=$($price)&category=Game&count=$($count)&start=0" - -# Список агентов для перебора -# $Agents = $( -# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", -# "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0", -# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.818.66 Safari/537.36 Edg/90.0.818.46", -# "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko", -# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.170", -# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Brave/90.0", -# "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Vivaldi/3.7" -# ) -# $userAgent = Get-Random -InputObject $Agents - -# v1 (HttpClientHandler) -# $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 - -# v2 (WebClient) -# $webClient = New-Object System.Net.WebClient -# $userAgent = Get-Random -InputObject $Agents -# $webClient.Headers.Add("User-Agent", $userAgent) -# $webClient.Headers.Add("Accept", "text/html") -# $content = $webClient.DownloadString($url) - -# v3 (2-й запрос из трассировки в браузере) -$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession -$session.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" -$response = Invoke-WebRequest -Uri $url -WebSession $session -Headers @{ - "Accept"="text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" - "Service-Worker-Navigation-Preload"="true" - "Upgrade-Insecure-Requests"="1" - "sec-ch-ua"="`"Chromium`";v=`"124`", `"Google Chrome`";v=`"124`", `"Not-A.Brand`";v=`"99`"" - "sec-ch-ua-mobile"="?0" - "sec-ch-ua-platform"="`"Windows`"" -} -$content = $response.Content - -# Логируем (проверяем содержимое) -Write-Host "---------------------- Content ----------------------" -Write-Host $content -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}/json/FreeGames.json" -$games | ConvertTo-Json -Depth 10 | Out-File $path \ No newline at end of file