WIP: Card Creator #51

Draft
waifu wants to merge 3 commits from card-creator into dev
6 changed files with 93 additions and 37 deletions
Showing only changes of commit 6130ac70a6 - Show all commits

View file

@ -32,6 +32,12 @@ def get_db_connection():
conn.row_factory = sqlite3.Row
return conn
def get_db_cursor():
"""Get a database cursor."""
if not hasattr(get_db_cursor, 'conn'):
get_db_cursor.conn = get_db_connection()
return get_db_cursor.conn.cursor()
@app.errorhandler(HTTPException)
def handle_exception(error):
return render_template("_error.html", error=error), error.code
@ -43,41 +49,41 @@ def i404():
@app.route('/')
def index():
conn = get_db_connection()
users = conn.execute('SELECT id, username FROM users').fetchall()
top_users = conn.execute('''
SELECT users.id, users.username, COUNT(pulls.id) AS pull_count
FROM users
LEFT JOIN pulls ON users.id = pulls.user_id
GROUP BY users.id
players = conn.execute('SELECT id, username FROM players').fetchall()
top_players = conn.execute('''
SELECT players.id, players.username, COUNT(pulls.id) AS pull_count
FROM players
LEFT JOIN pulls ON players.id = pulls.player_id
GROUP BY players.id
ORDER BY pull_count DESC
LIMIT 5
''').fetchall()
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>')
def user_profile(user_id):
@app.route('/player/<int:id>')
def player_profile(id):
conn = get_db_connection()
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.execute('SELECT * FROM users WHERE id = ?', (user_id,))
user = cursor.fetchone()
if user is None:
cursor.execute('SELECT * FROM players WHERE id = ?', (id,))
player = cursor.fetchone()
if player is None:
abort(404)
cursor.execute('''
SELECT pulls.timestamp, characters.name as character_name, characters.rarity
SELECT pulls.timestamp, cards.name as card_name, cards.rarity
FROM pulls
JOIN characters ON pulls.character_id = characters.id
WHERE pulls.user_id = ?
JOIN cards ON pulls.card_id = cards.id
WHERE pulls.player_id = ?
ORDER BY pulls.timestamp DESC
''', (user_id,))
''', (id,))
pulls = cursor.fetchall()
conn.close()
return render_template('user.html', user=user, pulls=pulls)
return render_template('player.html', player=player, pulls=pulls)
@app.route('/about')
def about():
@ -91,6 +97,16 @@ def submit_character():
def card():
return render_template('card_creator.html')
@app.route('/players')
def player_list():
# Replace with your actual player fetching logic
cursor = get_db_cursor()
cursor.execute('SELECT * FROM players')
players = cursor.fetchall()
if not players:
return render_template('player_list.html', players=[])
return render_template('player_list.html', players=players)
if __name__ == '__main__':
app.run(host=config.BIND_ADDRESS, port=config.WEB_PORT, debug=True)

View file

@ -28,10 +28,20 @@ along with this program. If not, see https://www.gnu.org/licenses/.
{% endif %}
&nbsp;|&nbsp;Kemoverse
</title>
</head>
<body>
<header>
{% block header %}{% endblock %}
<h1>Kemoverse</h1>
<p>A gacha in the fediverse.</p>
<nav>
<a href="{{ url_for('index') }}">Home</a>
<a href="{{ url_for('about') }}">About</a>
<a href="{{ url_for('submit_character') }}">Submit a Character</a>
<a href="{{ url_for('player_list') }}">Player List</a>
</nav>
</header>
<div class="container">
@ -39,8 +49,6 @@ along with this program. If not, see https://www.gnu.org/licenses/.
</div>
<footer>
<a class="footer-link" href="{{ url_for('about') }}">About</a>
<a class="footer-link" href="{{ url_for('submit_character') }}">Submit a Character</a>
{% block footer_extra %}{% endblock %}
</footer>
</body>

View file

@ -18,8 +18,8 @@ along with this program. If not, see https://www.gnu.org/licenses/.
{% extends "_base.html" %}
{% block content %}
<h1>About This Gacha</h1>
<p>This is a playful Misskey-themed gacha tracker made with Flask and SQLite.</p>
<h1>About This Site</h1>
<p>Kemoverse is a simple web app designed to track gacha pulls and player stats in a fun, competitive way.</p>
<p>All rolls are stored, stats are tracked, and characters are added manually for now.</p>
<p>Built with love, chaos, and way too much caffeine ☕.</p>
<a href="{{ url_for('index') }}">← Back to Home</a>

View file

@ -18,28 +18,19 @@ along with this program. If not, see https://www.gnu.org/licenses/.
{% extends "_base.html" %}
{% block header %}
<h1>Misskey Gacha Center</h1>
<p>Track your luck. Compare your pulls. Compete with friends.</p>
{% endblock %}
{% block content %}
<h2>🎖️ Leaderboard: Most Rolls</h2>
{% for user in top_users %}
{% for player in top_players %}
<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>
{% else %}
<p>No pulls yet. Be the first to roll!</p>
{% 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">
🚀 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" %}
{% block content %}
<div class="profile">
<h1>{{ user['username'] }}'s Gacha Rolls</h1>
<p>User ID: {{ user['id'] }}</p>
<h1>{{ player['username'] }}'s Gacha Rolls</h1>
<p>Player ID: {{ player['id'] }}</p>
<p>Total Rolls: {{ pulls | length }}</p>
</div>
@ -29,12 +29,12 @@ along with this program. If not, see https://www.gnu.org/licenses/.
{% for pull in pulls %}
<li>
<span class="timestamp">{{ pull['timestamp'] }}</span><br>
{{ pull['character_name'] }}
{{ pull['card_name'] }}
<span class="rarity">{{ '★' * pull['rarity'] }}</span>
</li>
{% endfor %}
</ul>
</div>
<a href="{{ url_for('index') }}">← Back to Users</a>
<a href="{{ url_for('index') }}">← Back to Home</a>
{% endblock %}

View file

@ -0,0 +1,41 @@
<!--
Kemoverse - a gacha-style bot for the Fediverse.
Copyright © 2025 Waifu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see https://www.gnu.org/licenses/.
-->
{% extends "_base.html" %}
{% block title %}Player List{% endblock %}
{% block content %}
<h1>Player List</h1>
{% if players and players|length > 0 %}
<ul>
{% for player in players %}
<li>
<a href="{{ url_for('player_profile', id=player['id']) }}">
{{ player['username'] }}
</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>No players found.</p>
{% endif %}
{% endblock %}
{% block footer_extra %}
<p>Player list is dynamically generated from the database.</p>
{% endblock %}