Compare commits

4 Commits
Author SHA1 Message Date
Sweetbread d63b3868cc Add polling
Docker Build and Push / build-and-push (push) Successful in 19s
2026-02-05 17:04:19 +03:00
Sweetbread b672b6be42 Update docker image 2026-02-05 17:03:37 +03:00
Sweetbread 53d14f9869 Add OG meta 2026-02-05 17:03:37 +03:00
Sweetbread c6fa9623f9 Add Steam info 2026-02-05 17:03:37 +03:00
3 changed files with 41 additions and 39 deletions

No files matched your search

+25 -25
View File
@@ -2,6 +2,7 @@ import os
import magic import magic
from pathlib import Path from pathlib import Path
from htmlmin import minify from htmlmin import minify
from time import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from musicbrainzngs import get_image_front from musicbrainzngs import get_image_front
from flask import ( from flask import (
@@ -16,19 +17,24 @@ from flask import (
from .modules.api.lb import listens, listening from .modules.api.lb import listens, listening
from .modules.api.steam import recent, owned from .modules.api.steam import recent, owned
def tmsmp(min: int) -> str: def tmsmp(sec: int) -> str:
if min < 60: if sec < 60:
return f"{min} m" return f"{sec} s"
elif min < 60*24: elif sec < 60*60:
return f"{min/60:.1f} h" return f"{sec/60:.1f} m"
elif sec < 60*60*24:
return f"{sec/60/60:.1f} h"
else: else:
return f"{min/60/24:.1f} d" return f"{sec/60/60/24:.1f} d"
def rtmsmp(unix: int) -> str: def utmsmp(unix: int) -> str:
return datetime \ return datetime \
.utcfromtimestamp(unix) \ .utcfromtimestamp(unix) \
.strftime('%Y-%m-%d %H:%M:%S') .strftime('%Y-%m-%d %H:%M:%S')
def rtmsmp(unix: int) -> str:
return tmsmp(int(time() - unix))
bp = Blueprint( bp = Blueprint(
"risdeveau", "risdeveau",
__name__, __name__,
@@ -61,26 +67,20 @@ def mb_cover(mbid):
.strftime('%a, %d %b %Y %H:%M:%S GMT') .strftime('%a, %d %b %Y %H:%M:%S GMT')
return r return r
args = {
"lb": listens,
"lb_now": listening,
"recent": recent,
"owned": owned,
"tmsmp": tmsmp,
"utmsmp": utmsmp,
"rtmsmp": rtmsmp
}
@bp.route("/") @bp.route("/")
def index(): def index():
return render_tmpl( return render_tmpl('index.html', **args)
'index.html',
lb=listens,
lb_now=listening,
recent=recent.get('data', {}),
owned=owned.get('data', {}),
tmsmp=tmsmp,
rtmsmp=rtmsmp
)
@bp.route("/m/<module>") @bp.route("/m/<module>")
def module(module): def module(module):
return render_tmpl( return render_tmpl(f'{module}.htm', **args)
f'{module}.htm',
lb=listens,
lb_now=listening,
recent=recent.get('data', {}),
owned=owned.get('data', {}),
tmsmp=tmsmp,
rtmsmp=rtmsmp
)
+2 -2
View File
@@ -3,7 +3,7 @@ from flask import Flask, jsonify
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger from apscheduler.triggers.interval import IntervalTrigger
import requests import requests
from datetime import datetime from time import time
import atexit import atexit
import re import re
from urllib.parse import urlparse, parse_qs from urllib.parse import urlparse, parse_qs
@@ -39,7 +39,7 @@ def api_request(cache, *args, **kwargs):
if response.status_code == 200: if response.status_code == 200:
cache.update({ cache.update({
'data': modify_game_list(response.json().get("response")), 'data': modify_game_list(response.json().get("response")),
'last_updated': datetime.now().isoformat(), 'last_updated': time(),
'status': 'success' 'status': 'success'
}) })
else: else:
+14 -12
View File
@@ -6,9 +6,9 @@
> >
<h2><a href="https://steamcommunity.com/id/risdeveau">Steam</a></h2> <h2><a href="https://steamcommunity.com/id/risdeveau">Steam</a></h2>
{% if recent.games %} {% if recent.data.games %}
<h3>Recently played:</h3> <h3>Recently played:</h3>
{% for g in recent.games %} {% for g in recent.data.games %}
<a href="https://store.steampowered.com/app/{{ g.appid }}" class="block"> <a href="https://store.steampowered.com/app/{{ g.appid }}" class="block">
<picture> <picture>
<source media="(max-width: 45rem)" srcset="{{ g.v_cover }}"> <source media="(max-width: 45rem)" srcset="{{ g.v_cover }}">
@@ -17,21 +17,22 @@
<div> <div>
<strong>{{ g.name }}</strong> <strong>{{ g.name }}</strong>
<p>Played last 2 weeks: {{ tmsmp(g.playtime_2weeks) }} <p>Played last 2 weeks: {{ tmsmp(g.playtime_2weeks*60) }}
<p> <p>
Total played: Total played:
{{ tmsmp(g.playtime_linux_forever) }} (<abbr title="On Linux">L</abbr>) + {{ tmsmp(g.playtime_linux_forever*60) }} (<abbr title="On Linux">L</abbr>) +
{{ tmsmp(g.playtime_windows_forever) }} (<abbr title="On Windows">W</abbr>) = {{ tmsmp(g.playtime_windows_forever*60) }} (<abbr title="On Windows">W</abbr>) =
{{ tmsmp(g.playtime_forever) }} (<abbr title="Total">T</abbr>) {{ tmsmp(g.playtime_forever*60) }} (<abbr title="Total">T</abbr>)
</p> </p>
</div> </div>
</a> </a>
{% endfor %} {% endfor %}
<p>Last updated: {{ rtmsmp(owned.last_updated) }} ago</p>
{% endif %} {% endif %}
{% if owned.games %} {% if owned.data.games %}
<h3>Top played games:</h3> <h3>Top played games:</h3>
{% set owned_games = owned.games | sort(attribute="playtime_forever", reverse=true) %} {% set owned_games = owned.data.games | sort(attribute="playtime_forever", reverse=true) %}
{% for g in owned_games[:5] %} {% for g in owned_games[:5] %}
<a href="https://store.steampowered.com/app/{{ g.appid }}" class="block"> <a href="https://store.steampowered.com/app/{{ g.appid }}" class="block">
<picture> <picture>
@@ -43,15 +44,16 @@
<strong>{{ g.name }}</strong> <strong>{{ g.name }}</strong>
<p> <p>
Total played: Total played:
{{ tmsmp(g.playtime_linux_forever) }} (<abbr title="On Linux">L</abbr>) + {{ tmsmp(g.playtime_linux_forever*60) }} (<abbr title="On Linux">L</abbr>) +
{{ tmsmp(g.playtime_windows_forever) }} (<abbr title="On Windows">W</abbr>) = {{ tmsmp(g.playtime_windows_forever*60) }} (<abbr title="On Windows">W</abbr>) =
{{ tmsmp(g.playtime_forever) }} (<abbr title="Total">T</abbr>) {{ tmsmp(g.playtime_forever*60) }} (<abbr title="Total">T</abbr>)
</p> </p>
{% if g.rtime_last_played != 0 %} {% if g.rtime_last_played != 0 %}
<p>Last played: {{ rtmsmp(g.rtime_last_played) }}</p> <p>Last played: {{ utmsmp(g.rtime_last_played) }}</p>
{% endif %} {% endif %}
</div> </div>
</a> </a>
{% endfor %} {% endfor %}
<p>Last updated: {{ rtmsmp(owned.last_updated) }} ago</p>
{% endif %} {% endif %}
</div> </div>