This commit is contained in:
mcinj 2022-06-01 07:58:06 -04:00
parent f3e6c165f4
commit 8010bbd750
4 changed files with 32 additions and 5 deletions

View file

@ -6,7 +6,7 @@ import sqlalchemy
from alembic import command from alembic import command
from alembic.config import Config from alembic.config import Config
from dateutil import tz from dateutil import tz
from sqlalchemy import func from sqlalchemy import func, select
from sqlalchemy.orm import Session, joinedload from sqlalchemy.orm import Session, joinedload
from sqlalchemy_utils import database_exists from sqlalchemy_utils import database_exists
@ -102,9 +102,20 @@ class GiveawayHelper:
with Session(engine) as session: with Session(engine) as session:
paginated_giveaways = paginate_sqlalchemy.SqlalchemyOrmPage(session.query(TableGiveaway) paginated_giveaways = paginate_sqlalchemy.SqlalchemyOrmPage(session.query(TableGiveaway)
.options(joinedload('steam_item')) .options(joinedload('steam_item'))
.order_by(TableGiveaway.giveaway_ended_at.desc()), page=page) .order_by(
TableGiveaway.giveaway_ended_at.desc()), page=page)
return paginated_giveaways return paginated_giveaways
@classmethod
def total_giveaways(cls):
with Session(engine) as session:
return session.execute(select(func.count(TableGiveaway.giveaway_id))).scalar_one()
@classmethod
def total_entered(cls):
with Session(engine) as session:
return session.query(TableGiveaway).filter_by(entered=True).count()
@classmethod @classmethod
def unix_timestamp_to_utc_datetime(cls, timestamp): def unix_timestamp_to_utc_datetime(cls, timestamp):
return datetime.utcfromtimestamp(timestamp) return datetime.utcfromtimestamp(timestamp)

View file

@ -11,6 +11,7 @@
<strong><nav> <strong><nav>
<ul class="menu"> <ul class="menu">
<li><a href="{{ url_for('config') }}">Config</a></li> <li><a href="{{ url_for('config') }}">Config</a></li>
<li><a href="{{ url_for('stats') }}">Stats</a></li>
<li><a href="{{ url_for('log_info') }}">Info Logs</a></li> <li><a href="{{ url_for('log_info') }}">Info Logs</a></li>
<li><a href="{{ url_for('log_debug') }}">Debug Logs</a></li> <li><a href="{{ url_for('log_debug') }}">Debug Logs</a></li>
<li><a href="{{ url_for('db_giveaways') }}">Giveaways</a></li> <li><a href="{{ url_for('db_giveaways') }}">Giveaways</a></li>

View file

@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block title %} {{name}} Steamgifts Bot Configuration {% endblock %}
{% block content %}
<ul>
<li>Total Giveaways Considered: {{totals}}</li>
<li>Giveaways Entered: {{entered}}</li>
</ul>
{% endblock %}

View file

@ -70,6 +70,12 @@ class WebServerThread(threading.Thread):
def db_giveaways(page): def db_giveaways(page):
return render_template('giveaways.html', name=self.prefix, data=GiveawayHelper.paginate(page=page)) return render_template('giveaways.html', name=self.prefix, data=GiveawayHelper.paginate(page=page))
@app.route(f"{self.app_root}stats")
def stats():
totals = GiveawayHelper.total_giveaways()
entered = GiveawayHelper.total_entered()
return render_template('stats.html', name=self.prefix, totals=totals, entered=entered)
if self.enabled: if self.enabled:
logger.info("Webserver Enabled. Running") logger.info("Webserver Enabled. Running")
if self.ssl: if self.ssl: