WIP: Website overhaul #60

Draft
waifu wants to merge 1 commit from website into dev
3 changed files with 24 additions and 30 deletions

View file

@ -43,41 +43,41 @@ def i404():
@app.route('/') @app.route('/')
def index(): def index():
conn = get_db_connection() conn = get_db_connection()
users = conn.execute('SELECT id, username FROM users').fetchall() players = conn.execute('SELECT id, username FROM players').fetchall()
top_users = conn.execute(''' top_players = conn.execute('''
SELECT users.id, users.username, COUNT(pulls.id) AS pull_count SELECT players.id, players.username, COUNT(pulls.id) AS pull_count
FROM users FROM players
LEFT JOIN pulls ON users.id = pulls.user_id LEFT JOIN pulls ON players.id = pulls.player_id
GROUP BY users.id GROUP BY players.id
ORDER BY pull_count DESC ORDER BY pull_count DESC
LIMIT 5 LIMIT 5
''').fetchall() ''').fetchall()
conn.close() conn.close()
return render_template('index.html', users=users, top_users=top_users) return render_template('index.html', players=players, top_players=top_players)
@app.route('/user/<int:user_id>') @app.route('/player/<int:id>')
def user_profile(user_id): def player_profile(id):
conn = get_db_connection() conn = get_db_connection()
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute('SELECT * FROM users WHERE id = ?', (user_id,)) cursor.execute('SELECT * FROM players WHERE id = ?', (id,))
user = cursor.fetchone() player = cursor.fetchone()
if user is None: if player is None:
abort(404) abort(404)
cursor.execute(''' cursor.execute('''
SELECT pulls.timestamp, characters.name as character_name, characters.rarity SELECT pulls.timestamp, cards.name as card_name, cards.rarity
FROM pulls FROM pulls
JOIN characters ON pulls.character_id = characters.id JOIN cards ON pulls.card_id = cards.id
WHERE pulls.user_id = ? WHERE pulls.player_id = ?
ORDER BY pulls.timestamp DESC ORDER BY pulls.timestamp DESC
''', (user_id,)) ''', (id,))
pulls = cursor.fetchall() pulls = cursor.fetchall()
conn.close() conn.close()
return render_template('user.html', user=user, pulls=pulls) return render_template('player.html', player=player, pulls=pulls)
@app.route('/about') @app.route('/about')
def about(): def about():

View file

@ -19,27 +19,21 @@ along with this program. If not, see https://www.gnu.org/licenses/.
{% extends "_base.html" %} {% extends "_base.html" %}
{% block header %} {% block header %}
<h1>Misskey Gacha Center</h1> <h1>Kemoverse</h1>
<p>Track your luck. Compare your pulls. Compete with friends.</p> <p>Track your luck. Compare your pulls. Compete with friends.</p>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h2>🎖️ Leaderboard: Most Rolls</h2> <h2>🎖️ Leaderboard: Most Rolls</h2>
{% for user in top_users %} {% for player in top_players %}
<div class="leaderboard-entry"> <div class="leaderboard-entry">
{{ loop.index }}. <strong>{{ user['username'] }}</strong> — {{ user['pull_count'] }} rolls {{ loop.index }}. <strong>{{ player['username'] }}</strong> — {{ player['pull_count'] }} rolls
</div> </div>
{% else %} {% else %}
<p>No pulls yet. Be the first to roll!</p> <p>No pulls yet. Be the first to roll!</p>
{% endfor %} {% endfor %}
<h2>📋 All Registered Users</h2>
<ul>
{% for user in users %}
<li><a href="{{ url_for('user_profile', user_id=user['id']) }}">{{ user['username'] }}</a></li>
{% endfor %}
</ul>
<div class="note"> <div class="note">
🚀 This is a fun little gacha tracker! More features coming soon. Want to help shape it? 🚀 This is a fun little gacha tracker! More features coming soon. Want to help shape it?

View file

@ -18,8 +18,8 @@ along with this program. If not, see https://www.gnu.org/licenses/.
{% extends "_base.html" %} {% extends "_base.html" %}
{% block content %} {% block content %}
<div class="profile"> <div class="profile">
<h1>{{ user['username'] }}'s Gacha Rolls</h1> <h1>{{ player['username'] }}'s Gacha Rolls</h1>
<p>User ID: {{ user['id'] }}</p> <p>Player ID: {{ player['id'] }}</p>
<p>Total Rolls: {{ pulls | length }}</p> <p>Total Rolls: {{ pulls | length }}</p>
</div> </div>
@ -29,12 +29,12 @@ along with this program. If not, see https://www.gnu.org/licenses/.
{% for pull in pulls %} {% for pull in pulls %}
<li> <li>
<span class="timestamp">{{ pull['timestamp'] }}</span><br> <span class="timestamp">{{ pull['timestamp'] }}</span><br>
{{ pull['character_name'] }} {{ pull['card_name'] }}
<span class="rarity">{{ '★' * pull['rarity'] }}</span> <span class="rarity">{{ '★' * pull['rarity'] }}</span>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<a href="{{ url_for('index') }}">← Back to Users</a> <a href="{{ url_for('index') }}">← Back to Home</a>
{% endblock %} {% endblock %}