Add Steam info
Docker Build and Push / build-and-push (push) Successful in 55s

This commit is contained in:
2026-02-04 00:34:16 +03:00
parent bc8947dfac
commit 23bd539799
5 changed files with 154 additions and 1 deletions
+25 -1
View File
@@ -13,6 +13,20 @@ from flask import (
)
from .modules.api.lb import listens, listening
from .modules.api.steam import recent, owned
def tmsmp(min: int) -> str:
if min < 60:
return f"{min} m"
elif min < 60*24:
return f"{min/60:.1f} h"
else:
return f"{min/60/24:.1f} d"
def rtmsmp(unix: int) -> str:
return datetime \
.utcfromtimestamp(unix) \
.strftime('%Y-%m-%d %H:%M:%S')
bp = Blueprint(
"risdeveau",
@@ -47,4 +61,14 @@ def mb_cover(mbid):
@bp.route("/")
def index():
return render_tmpl('index.html', lb=listens, lb_now=listening)
print(recent)
return render_tmpl(
'index.html',
lb=listens,
lb_now=listening,
recent=recent.get('data', {}),
owned=owned.get('data', {}),
tmsmp=tmsmp,
rtmsmp=rtmsmp
)
+65
View File
@@ -0,0 +1,65 @@
from os import environ
from flask import Flask, jsonify
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
import requests
from datetime import datetime
import atexit
import re
from urllib.parse import urlparse, parse_qs
TOKEN = environ.get("STEAM_TOKEN")
MY_ID = 76561198826355942
recent = {}
owned = {}
def get_cover_url(appid: int) -> str:
return f"https://shared.fastly.steamstatic.com/store_item_assets//steam/apps/{appid}/header.jpg"
def inject_cover_url(json: dict) -> dict:
if 'games' in json.keys():
for i, g in enumerate(json['games']):
json['games'][i]['img_icon_url'] = get_cover_url(g['appid'])
return json
def steam_request(interface: str, method: str, v: int = 1, **kwargs) -> requests.Response:
return requests.get(
f"https://api.steampowered.com/{interface}/{method}/v{v:04}/",
params=dict({"key": TOKEN}, **kwargs),
timeout=10
)
def api_request(cache, *args, **kwargs):
try:
response = steam_request(*args, **kwargs)
if response.status_code == 200:
cache.update({
'data': inject_cover_url(response.json().get("response")),
'last_updated': datetime.now().isoformat(),
'status': 'success'
})
else:
cache['status'] = f'error: {response.status_code}'
except Exception as e:
cache['status'] = f'error: {str(e)}'
scheduler = BackgroundScheduler()
scheduler.add_job(
func=lambda: api_request(recent, "IPlayerService", "GetRecentlyPlayedGames", steamid=76561198826355942),
trigger=IntervalTrigger(minutes=15),
id='risdeveau.steam.recent',
replace_existing=True
)
scheduler.add_job(
func=lambda: api_request(owned, "IPlayerService", "GetOwnedGames", steamid=76561198826355942, include_appinfo=1, include_played_free_games=1),
trigger=IntervalTrigger(minutes=15),
id='risdeveau.steam.recent',
replace_existing=True
)
scheduler.start()
api_request(recent, "IPlayerService", "GetRecentlyPlayedGames", steamid=76561198826355942)
api_request(owned, "IPlayerService", "GetOwnedGames", steamid=76561198826355942, include_appinfo=1, include_played_free_games=1)
atexit.register(lambda: scheduler.shutdown())
@@ -48,6 +48,24 @@ h3 {
}
}
.steam {
.block {
display: flex;
align-items: stretch;
img {
height: 6rem;
flex: 0 0 auto;
margin-right: .5rem;
}
p {
flex: 1;
margin: .5rem 0;
}
}
}
table, tbody {
vertical-align: baseline;
border-collapse: collapse;
@@ -24,6 +24,7 @@
'info',
'contacts',
'listenbrainz',
'steam',
'donate',
'88x31'
) %}
+45
View File
@@ -0,0 +1,45 @@
<div class="block steam">
<h2><a href="https://steamcommunity.com/id/risdeveau">Steam</a></h2>
<h3>Recently played:</h3>
{% for g in recent.games %}
<a href="https://store.steampowered.com/app/{{ g.appid }}" class="block">
<img src="{{ g.img_icon_url }}"/>
<div>
<strong>{{ g.name }}</strong>
<p>Played last 2 weeks: {{ tmsmp(g.playtime_2weeks) }}
<p>
Total played:
{{ tmsmp(g.playtime_linux_forever) }} (<abbr title="On Linux">L</abbr>) +
{{ tmsmp(g.playtime_windows_forever) }} (<abbr title="On Windows">W</abbr>) =
{{ tmsmp(g.playtime_forever) }} (<abbr title="Total">T</abbr>)
</p>
</div>
</a>
{% endfor %}
<h3>Top played games:</h3>
{% set owned_games = owned.games | sort(attribute="playtime_forever", reverse=true) %}
{% for g in owned_games[:5] %}
<a href="https://store.steampowered.com/app/{{ g.appid }}" class="block">
<img src="{{ g.img_icon_url }}"/>
<div>
<strong>{{ g.name }}</strong>
{% if g.playtime_2weeks %}
<p>Played last 2 weeks: {{ tmsmp(g.playtime_2weeks) }}
{% endif %}
<p>
Total played:
{{ tmsmp(g.playtime_linux_forever) }} (<abbr title="On Linux">L</abbr>) +
{{ tmsmp(g.playtime_windows_forever) }} (<abbr title="On Windows">W</abbr>) =
{{ tmsmp(g.playtime_forever) }} (<abbr title="Total">T</abbr>)
</p>
{% if g.rtime_last_played != 0 %}
<p>Last played: {{ rtmsmp(g.rtime_last_played) }}</p>
{% endif %}
</div>
</a>
{% endfor %}
</div>