better handling of ITAD API and such
This commit is contained in:
parent
49fdd243d0
commit
171719a85f
49
setup.sh
49
setup.sh
|
@ -163,25 +163,26 @@ EOL
|
||||||
|
|
||||||
# app.py (the main app)
|
# app.py (the main app)
|
||||||
cat <<'PYTHON_END' > app.py
|
cat <<'PYTHON_END' > app.py
|
||||||
# Standards
|
# Standard library imports
|
||||||
import atexit
|
import atexit
|
||||||
import csv
|
import csv
|
||||||
import io
|
import io
|
||||||
import locale
|
import locale # Note: locale was in your imports but not standard for typical web apps unless specific use.
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
import sqlite3
|
import sqlite3 # Note: direct sqlite3 import is unusual if you're using SQLAlchemy for all DB ops.
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from io import BytesIO
|
from io import BytesIO # Note: io.BytesIO is good, no need for direct BytesIO import if io is already imported.
|
||||||
from time import sleep
|
from time import sleep # Note: time.sleep is fine, no need for direct 'sleep' import if 'time' is imported.
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
import warnings
|
||||||
|
|
||||||
# 3rd-Provider-Modules
|
# 3rd-Provider-Modules
|
||||||
import pytz
|
import pytz
|
||||||
|
@ -254,6 +255,7 @@ def enable_foreign_keys(dbapi_connection, connection_record):
|
||||||
cursor.execute("PRAGMA foreign_keys=ON;")
|
cursor.execute("PRAGMA foreign_keys=ON;")
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
|
ITAD_API_KEY_PLACEHOLDER = "your_api_key_here"
|
||||||
TZ = os.getenv('TZ', 'UTC')
|
TZ = os.getenv('TZ', 'UTC')
|
||||||
os.environ['TZ'] = TZ
|
os.environ['TZ'] = TZ
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -346,6 +348,7 @@ app.config.update(
|
||||||
SESSION_COOKIE_SAMESITE = 'Lax',
|
SESSION_COOKIE_SAMESITE = 'Lax',
|
||||||
PERMANENT_SESSION_LIFETIME = timedelta(days=30),
|
PERMANENT_SESSION_LIFETIME = timedelta(days=30),
|
||||||
|
|
||||||
|
|
||||||
# LOGIN COOKIE STUFF
|
# LOGIN COOKIE STUFF
|
||||||
REMEMBER_COOKIE_DURATION=timedelta(days=30),
|
REMEMBER_COOKIE_DURATION=timedelta(days=30),
|
||||||
REMEMBER_COOKIE_HTTPONLY=True,
|
REMEMBER_COOKIE_HTTPONLY=True,
|
||||||
|
@ -618,7 +621,8 @@ def parse_steam_release_date(date_str):
|
||||||
|
|
||||||
def fetch_itad_slug(steam_appid: int) -> str | None:
|
def fetch_itad_slug(steam_appid: int) -> str | None:
|
||||||
api_key = os.getenv("ITAD_API_KEY")
|
api_key = os.getenv("ITAD_API_KEY")
|
||||||
if not api_key:
|
if not api_key or api_key.strip() == "your-secret-key-here":
|
||||||
|
app.logger.warning("ITAD-API-Key ist nicht gesetzt oder ist ein Platzhalter.")
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
|
@ -635,8 +639,8 @@ def fetch_itad_slug(steam_appid: int) -> str | None:
|
||||||
|
|
||||||
def fetch_itad_game_id(steam_appid: int) -> str | None:
|
def fetch_itad_game_id(steam_appid: int) -> str | None:
|
||||||
api_key = os.getenv("ITAD_API_KEY")
|
api_key = os.getenv("ITAD_API_KEY")
|
||||||
if not api_key:
|
if not api_key or api_key.strip() == "your-secret-key-here":
|
||||||
app.logger.error("ITAD_API_KEY nicht gesetzt")
|
app.logger.warning("ITAD-API-Key ist nicht gesetzt oder ist ein Platzhalter.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -655,11 +659,12 @@ def fetch_itad_game_id(steam_appid: int) -> str | None:
|
||||||
app.logger.error(f"ITAD Error: {str(e)}")
|
app.logger.error(f"ITAD Error: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def fetch_itad_prices(game_id: str) -> dict | None:
|
def fetch_itad_prices(game_id: str) -> dict | None:
|
||||||
api_key = os.getenv("ITAD_API_KEY")
|
api_key = os.getenv("ITAD_API_KEY")
|
||||||
country = os.getenv("ITAD_COUNTRY", "DE")
|
country = os.getenv("ITAD_COUNTRY", "DE")
|
||||||
if not api_key:
|
|
||||||
|
if not api_key or api_key.strip() == "your-secret-key-here":
|
||||||
|
app.logger.warning("ITAD-API-Key ist nicht gesetzt oder ist ein Platzhalter.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -677,7 +682,7 @@ def fetch_itad_prices(game_id: str) -> dict | None:
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()[0]
|
return response.json()[0]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"ITAD-Preisabfrage fehlgeschlagen: {str(e)}")
|
app.logger.error(f"ITAD-Preisabfrage fehlgeschlagen: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
@ -1770,7 +1775,7 @@ cat <<HTML_END > templates/login.html
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-md-6 col-lg-4">
|
<div class="col-md-6 col-lg-4">
|
||||||
<h1 class="mb-4">{{ _('Login') }}</h1>
|
<h1 class="mb-4 text-center">{{ _('Login') }}</h1>
|
||||||
<form method="POST" aria-label="{{ _('Login form') }}" autocomplete="on">
|
<form method="POST" aria-label="{{ _('Login form') }}" autocomplete="on">
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
|
@ -1794,23 +1799,29 @@ cat <<HTML_END > templates/login.html
|
||||||
autocomplete="current-password"
|
autocomplete="current-password"
|
||||||
aria-required="true">
|
aria-required="true">
|
||||||
</div>
|
</div>
|
||||||
{% if error %}
|
<div class="mb-3 form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="remember_me" name="remember_me" value="true">
|
||||||
|
<label class="form-check-label" for="remember_me">{{ _('Remember me') }}</label>
|
||||||
|
</div>
|
||||||
|
{# Flash messages are handled in base.html, so the specific error block here can be removed #}
|
||||||
|
{# {% if error %}
|
||||||
<div class="alert alert-danger" role="alert">
|
<div class="alert alert-danger" role="alert">
|
||||||
{{ error }}
|
{{ error }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %} #}
|
||||||
<button type="submit" class="btn btn-primary w-100">{{ _('Login') }}</button>
|
|
||||||
|
<button type="submit" class="btn btn-primary w-100 mb-3">{{ _('Login') }}</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{% if config.REGISTRATION_ENABLED %}
|
||||||
<div class="mt-3 text-center">
|
<div class="mt-3 text-center">
|
||||||
{% if config['REGISTRATION_ENABLED'] %}
|
<a href="{{ url_for('register') }}">{{ _('No account? Register here!') }}</a>
|
||||||
<a href="{{ url_for('register') }}">{{ _('No account? Register here!') }}</a>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
HTML_END
|
HTML_END
|
||||||
|
|
||||||
# Register Template
|
# Register Template
|
||||||
|
|
Loading…
Reference in New Issue