You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
kemoverse/web/app.py

59 lines
1.6 KiB

from flask import Flask, render_template
import sqlite3
app = Flask(__name__)
DB_PATH = "./gacha_game.db" # Adjust path if needed
def get_db_connection():
conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row
return conn
@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
ORDER BY pull_count DESC
LIMIT 5
''').fetchall()
conn.close()
return render_template('index.html', users=users, top_users=top_users)
@app.route('/user/<int:user_id>')
def user_profile(user_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()
cursor.execute('''
SELECT pulls.timestamp, characters.name as character_name, characters.rarity
FROM pulls
JOIN characters ON pulls.character_id = characters.id
WHERE pulls.user_id = ?
ORDER BY pulls.timestamp DESC
''', (user_id,))
pulls = cursor.fetchall()
conn.close()
return render_template('user.html', user=user, pulls=pulls)
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/submit')
def submit_character():
return render_template('submit.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)