Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicconike committed Jun 7, 2024
1 parent 25d0a2d commit 8762684
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 42 deletions.
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Mandatory Envioronment Variables for Steam Stats
INPUT_GH_TOKEN=<YOUR_GITHUB_TOKEN_KEY>
# Mandatory Environment Variables for Steam Stats
INPUT_GH_TOKEN=<YOUR_GITHUB_TOKEN>
INPUT_STEAM_API_KEY=<YOUR_STEAM_API_KEY>
INPUT_STEAM_ID=<YOUR_STEAM_ID> #17 digit SteamID(steamID64 [Decimals])
INPUT_STEAM_CUSTOM_ID=<YOUR_STEAM_CUSTOM_ID>

# Optional Feature Flags
INPUT_WORKSHOP_STATS=<True or False>
INPUT_LOG_SCALE=<True or False>
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ schedule:
- cron: "30 18 * * 0"
```
## Samples (From my Steam Account)
**Example for Steam User Stats**
<!-- Steam-Stats start -->
![Steam Summary](https://github.com/Nicconike/Steam-Stats/blob/master/assets/steam_summary.png)
![Recently Played Games](https://github.com/Nicconike/Steam-Stats/blob/master/assets/recently_played_games.png)
<!-- Steam-Stats end -->
**Example for Steam Workshop Stats**
<!-- Steam-Workshop start -->
![Steam Workshop Stats](https://github.com/Nicconike/Steam-Stats/blob/master/assets/steam_workshop_stats.png)
<!-- Steam-Workshop end -->
## Update Readme
1. Add this comment in your markdown file(Readme.md) which is for Steam User Stats
```md
Expand All @@ -46,28 +58,15 @@ schedule:
1. Steam User Stats (Required | Default)
1. Steam Player Summary
2. Steam's Recently Played Games in the last 2 weeks
1. The Graph plot for recently played games is by default implemented in a fixed scale but if you want you can update it to be in a logarithmic scale by using this flag

`LOG_SCALE: True`

**Example for Steam User Stats**
<!-- Steam-Stats start -->
![Steam Summary](https://github.com/Nicconike/Steam-Stats/blob/master/assets/steam_summary.png)
![Steam Summary](https://github.com/Nicconike/Steam-Stats/blob/master/assets/recently_played_games.png)
<!-- Steam-Stats end -->

1. Steam Workshop Stats (Optional)
1. Workshop Stats Module can be activated/used by adding this flag in the workflow file in the environment variables

`WORKSHOP_STATS: True`

1. The Graph plot for recently played games is by default implemented in a fixed scale but if you want you can update it to be in a logarithmic scale by using this flag: `LOG_SCALE: True`
2. When `LOG_SCALE` is `False`
![Recently Played Games](https://github.com/Nicconike/Steam-Stats/blob/master/assets/recently_played_games(linear).png)
3. When `LOG_SCALE` is `True`
![Recently Played Games](https://github.com/Nicconike/Steam-Stats/blob/master/assets/recently_played_games(logarithmic).png)
2. Steam Workshop Stats (Optional)
1. Workshop Stats Module can be activated/used by adding this flag in the workflow file in the environment variables: `WORKSHOP_STATS: True`
2. This module displays the total number of Unique Visitors, Subscribers and Favorites

**Example for Steam Workshop Stats**
<!-- Steam-Workshop start -->
![Steam Summary](https://github.com/Nicconike/Steam-Stats/blob/master/assets/steam_workshop_stats.png)
<!-- Steam-Workshop end -->

## Setup with Example
After completing the steps mentioned in the [Prerequisites](#Prerequisites), you have to save all the mentioned keys(except markdown comments) like github token,api key, steamid, customid as Secrets in your Github repo's settings.

Expand Down
19 changes: 13 additions & 6 deletions api/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import zipfile
from pyppeteer import launch, errors
import requests
from dotenv import load_dotenv

REQUEST_TIMEOUT = (10, 15)
load_dotenv()

REQUEST_TIMEOUT = (25, 30)

CHROMIUM_ZIP_URL = (
"https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win_x64/1309077/"
Expand Down Expand Up @@ -276,6 +279,8 @@ def generate_card_for_played_games(games_data):
if not games_data:
return None

# Check if LOG_SCALE is set to true
log_scale = os.getenv("INPUT_LOG_SCALE", "false").lower() == "true"
max_playtime = games_data["response"]["games"][0]["playtime_2weeks"]

# Generate the progress bars with repeating styles
Expand All @@ -286,9 +291,11 @@ def generate_card_for_played_games(games_data):
playtime = game["playtime_2weeks"]
img_icon_url = f"https://media.steampowered.com/steamcommunity/public/images/apps/{
game["appid"]}/{game["img_icon_url"]}.jpg"
normalized_playtime = (playtime / max_playtime) * 100
normalized_playtime = math.log1p(playtime) / math.log1p(
max(game["playtime_2weeks"] for game in games_data["response"]["games"])) * 100
if log_scale is True:
normalized_playtime = math.log1p(playtime) / math.log1p(
max(game["playtime_2weeks"] for game in games_data["response"]["games"])) * 100
else:
normalized_playtime = (playtime / max_playtime) * 100

normalized_playtime = round(normalized_playtime)
display_time = f"{playtime} mins" if playtime < 60 else f"{
Expand Down Expand Up @@ -329,7 +336,7 @@ def generate_card_for_played_games(games_data):
"assets/recently_played_games.png", ".card")

return (
"![Steam Summary]"
"![Recently Played Games]"
"(https://github.com/Nicconike/Steam-Stats/blob/master/assets/recently_played_games.png)"
)

Expand Down Expand Up @@ -417,6 +424,6 @@ def generate_card_for_steam_workshop(workshop_stats):
"assets/steam_workshop_stats.png", ".card")

return (
"![Steam Summary]"
"![Steam Workshop Stats]"
"(https://github.com/Nicconike/Steam-Stats/blob/master/assets/steam_workshop_stats.png)"
)
16 changes: 11 additions & 5 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
STEAM_CUSTOM_ID = os.environ["INPUT_STEAM_CUSTOM_ID"]

# Optional Feature Flags
WORKSHOP_STATS = os.getenv("WORKSHOP_STATS", "false").lower() == "true"
LOG_SCALE = os.getenv("LOG_SCALE", "false").lower() == "true"
WORKSHOP_STATS = os.getenv("INPUT_WORKSHOP_STATS", "false").lower() == "true"
LOG_SCALE = os.getenv("INPUT_LOG_SCALE", "false").lower() == "true"


def update_readme(markdown_data, start_marker, end_marker, readme_path="README.md"):
Expand Down Expand Up @@ -65,10 +65,10 @@ def update_readme(markdown_data, start_marker, end_marker, readme_path="README.m
if summary_content and recent_games:
USER_MARKDOWN_CONTENT += summary_content
USER_MARKDOWN_CONTENT += recent_games
print("Successfully retrieved Steam User Data")
print("Retrieved all Steam User Stats")
else:
print(
"Failed to generate HTML content for Steam Summary or Recently Played Games")
"Failed to generate card data for Steam Summary & Recently Played Games")
else:
print("Failed to fetch Steam Summary & Games Data")

Expand All @@ -93,4 +93,10 @@ def update_readme(markdown_data, start_marker, end_marker, readme_path="README.m

end_time = time.time() # End the timer
total_time = round(end_time-start_time, 3) # Total time
print(f"Total Execution Time: {total_time} seconds")
if total_time > 60:
minutes = total_time // 60
seconds = total_time % 60
print(f"Total Execution Time: {int(minutes)
} minutes and {seconds:.3f} seconds")
else:
print(f"Total Execution Time: {total_time} seconds")
2 changes: 1 addition & 1 deletion api/steam_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
STEAM_API_KEY = os.environ["INPUT_STEAM_API_KEY"]

# A reasonable timeout for the request (connection and read timeout)
REQUEST_TIMEOUT = (10, 15)
REQUEST_TIMEOUT = (25, 30)

# Steam Web API endpoints
PLAYER_SUMMARIES = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/"
Expand Down
2 changes: 1 addition & 1 deletion api/steam_workshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


# A reasonable timeout for the request (connection and read timeout)
REQUEST_TIMEOUT = (10, 15)
REQUEST_TIMEOUT = (25, 30)

GET_SERVER_INFO_URL = 'https://api.steampowered.com/ISteamWebAPIUtil/GetServerInfo/v1/'

Expand Down
Binary file added assets/recently_played_games(linear).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/recently_played_games(logarithmic).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions assets/recently_played_games.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ <h2>Recently Played Games</h2>
<img src="https://media.steampowered.com/steamcommunity/public/images/apps/730/8dbc71957312bbd3baea65848b545be9eae2a355.jpg" alt="Counter-Strike 2" class="game-icon">
<progress class="progress-style-1" value="100"
max="100"></progress>
<span class="game-info"><b>Counter-Strike 2 (5.82 hrs)</b></span>
<span class="game-info"><b>Counter-Strike 2 (7.77 hrs)</b></span>
</div>

<div class="bar-container">
<img src="https://media.steampowered.com/steamcommunity/public/images/apps/1521580/78a54aba83ed0dc7039b2f3afd232dfc41f79c44.jpg" alt="Perfect Heist 2" class="game-icon">
<progress class="progress-style-2" value="50"
<progress class="progress-style-2" value="48"
max="100"></progress>
<span class="game-info"><b>Perfect Heist 2 (18 mins)</b></span>
</div>

<div class="bar-container">
<img src="https://media.steampowered.com/steamcommunity/public/images/apps/431960/72edaed9d748c6cf7397ffb1c83f0b837b9ebd9d.jpg" alt="Wallpaper Engine" class="game-icon">
<progress class="progress-style-3" value="39"
<progress class="progress-style-3" value="37"
max="100"></progress>
<span class="game-info"><b>Wallpaper Engine (9 mins)</b></span>
</div>
Expand Down
Binary file modified assets/recently_played_games.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions assets/steam_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ <h2 id="name">Name: Nicco</h2>
</p>
</div>
<div class="info-right">
<p id="lastlogoff">Last Logoff: 05/06/2024</p>
<p id="timecreated">Gaming Since: 12/07/2017</p>
<p id="lastlogoff">Last Logoff: 07/06/2024</p>
<p id="timecreated">PC Gaming Since: 12/07/2017</p>
</div>
</div>

Expand Down
Binary file modified assets/steam_summary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions assets/steam_workshop_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ <h2>Steam Workshop Stats</h2>
<tbody>
<tr>
<td>Unique Visitors</td>
<td>3014</td>
<td>3035</td>
</tr>
<tr>
<td>Current Subscribers</td>
<td>1775</td>
<td>1797</td>
</tr>
<tr>
<td>Current Favorites</td>
Expand Down
Binary file modified assets/steam_workshop_stats.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 8762684

@vercel
Copy link

@vercel vercel bot commented on 8762684 Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.