File size: 896 Bytes
f073e54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sqlite3

def create_table():
    conn = sqlite3.connect("code.db")
    cursor = conn.cursor()
    cursor.execute("DELETE FROM code;")
    with open('code.txt', 'r') as f:
        c = 0
        txt = ""
        id = 1
        for l in f :
            txt += l
            if l == ";;;\n":
                c += 1
            if c == 4 :
                tab = txt.split(";;;\n")
                txt = ""
                c = 0
                cursor.execute("INSERT INTO code (id, titre, enonce, code_trous, test) VALUES (?, ?, ?, ?, ?)", (id, tab[0].replace("\n",""), tab[1], tab[2], tab[3]))
                id += 1
        conn.commit()
        conn.close()

def return_exercise(titre):
    conn = sqlite3.connect("code.db")
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM code WHERE titre = ?", (titre,))
    rows = cursor.fetchall()
    conn.close()
    return rows[0]