File size: 2,681 Bytes
cfef158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
79
import sqlite3
from datetime import datetime

def get_db_connection():
    return sqlite3.connect('bharat_play.db')

def save_submission(submission_data):
    conn = get_db_connection()
    c = conn.cursor()
    try:
        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"Error saving submission: {e}")
        return False
    finally:
        conn.close()

def get_user_submissions(username):
    conn = get_db_connection()
    c = conn.cursor()
    try:
        # First check if the table exists
        c.execute('''SELECT name FROM sqlite_master 

                    WHERE type='table' AND name='submissions';''')
        if not c.fetchone():
            print("Submissions table does not exist")
            return []
            
        # If table exists, get the submissions
        c.execute('''SELECT * FROM submissions 

                    WHERE name = ? 

                    ORDER BY timestamp DESC''', (username,))
        columns = [description[0] for description in c.description]
        results = []
        for row in c.fetchall():
            results.append(dict(zip(columns, row)))
        return results
    except Exception as e:
        print(f"Error getting submissions: {e}")
        return []
    finally:
        conn.close()

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