1
File size: 2,178 Bytes
43566ea
3f1eced
43566ea
 
3f1eced
e339afc
43566ea
e339afc
43566ea
 
 
 
3f1eced
43566ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f1eced
43566ea
 
 
 
 
 
 
3f1eced
 
e339afc
 
43566ea
3f1eced
43566ea
 
 
 
 
 
 
3f1eced
43566ea
e339afc
 
43566ea
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sqlite3
import os
from datetime import datetime

DB_PATH = os.path.join(os.path.dirname(__file__), "..", "bharat_play.db")

def get_db_connection():
    return sqlite3.connect(DB_PATH)

def save_submission(submission_data):
    conn = get_db_connection()
    try:
        c = conn.cursor()
        c.execute('''
            INSERT INTO submissions 
            (name, title, description, category, player_count, age_group, 
             equipment_needed, input_type, audio_url, image_url, video_url, 
             lat, lon, timestamp)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        ''', (
            submission_data['name'],
            submission_data['title'],
            submission_data['description'],
            submission_data['category'],
            submission_data['player_count'],
            submission_data['age_group'],
            submission_data['equipment_needed'],
            submission_data['input_type'],
            submission_data['audio_url'],
            submission_data['image_url'],
            submission_data['video_url'],
            submission_data['lat'],
            submission_data['lon'],
            datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        ))
        conn.commit()
        return True
    except Exception as e:
        print(f"❌ Submission save error: {e}")
        return False
    finally:
        conn.close()

def get_user_submissions(username):
    conn = get_db_connection()
    try:
        c = conn.cursor()
        c.execute('''SELECT * FROM submissions WHERE name = ? ORDER BY timestamp DESC''', (username,))
        columns = [desc[0] for desc in c.description]
        return [dict(zip(columns, row)) for row in c.fetchall()]
    except Exception as e:
        print(f"❌ Error fetching user submissions: {e}")
        return []
    finally:
        conn.close()

def get_all_submissions():
    conn = get_db_connection()
    try:
        c = conn.cursor()
        c.execute('SELECT * FROM submissions ORDER BY timestamp DESC')
        columns = [desc[0] for desc in c.description]
        return [dict(zip(columns, row)) for row in c.fetchall()]
    finally:
        conn.close()