Skip to content

Commit

Permalink
update module
Browse files Browse the repository at this point in the history
  • Loading branch information
Lifailon committed May 11, 2024
1 parent 3f244af commit 210ec9a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 65 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# EpicGames Statistics
# Epic Games Stats

Данный рипозиторий содержит списки игр, который ежедневно обновляется с помощью GitHub Actions.

Expand Down
File renamed without changes.
65 changes: 65 additions & 0 deletions module/Get-GameList.ps1
Original file line number Diff line number Diff line change
@@ -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
58 changes: 0 additions & 58 deletions scripts/FreeGamesList.ps1

This file was deleted.

0 comments on commit 210ec9a

Please sign in to comment.