Spaces:
Running
Running
Delete database.py
Browse files- database.py +0 -54
database.py
DELETED
@@ -1,54 +0,0 @@
|
|
1 |
-
import sqlite3
|
2 |
-
|
3 |
-
def create_table():
|
4 |
-
conn = sqlite3.connect("code.db")
|
5 |
-
cursor = conn.cursor()
|
6 |
-
cursor.execute("DELETE FROM code;")
|
7 |
-
with open('code.txt', 'r') as f:
|
8 |
-
c = 0
|
9 |
-
txt = ""
|
10 |
-
id = 1
|
11 |
-
for l in f :
|
12 |
-
txt += l
|
13 |
-
if l == ";;;\n":
|
14 |
-
c += 1
|
15 |
-
if c == 5 :
|
16 |
-
tab = txt.split(";;;\n")
|
17 |
-
txt = ""
|
18 |
-
c = 0
|
19 |
-
cursor.execute("INSERT INTO code (id, titre, niveau, mots_cle, enonce, test) VALUES (?, ?, ?, ?, ?, ?)", (id, tab[0], tab[1], tab[2], tab[3], tab[4]))
|
20 |
-
id += 1
|
21 |
-
conn.commit()
|
22 |
-
conn.close()
|
23 |
-
|
24 |
-
def return_title():
|
25 |
-
conn = sqlite3.connect("code.db")
|
26 |
-
cursor = conn.cursor()
|
27 |
-
cursor.execute("SELECT id, titre, niveau FROM code")
|
28 |
-
rows = cursor.fetchall()
|
29 |
-
conn.close()
|
30 |
-
return [{"id" : v[0], "title" : v[1].replace("\n",""), "niveau":v[2]} for v in rows]
|
31 |
-
|
32 |
-
def return_exercise(id):
|
33 |
-
conn = sqlite3.connect("code.db")
|
34 |
-
cursor = conn.cursor()
|
35 |
-
cursor.execute("SELECT * FROM code WHERE id = ?", (id,))
|
36 |
-
rows = cursor.fetchall()
|
37 |
-
conn.close()
|
38 |
-
return rows[0]
|
39 |
-
|
40 |
-
def return_mot_cle():
|
41 |
-
conn = sqlite3.connect("code.db")
|
42 |
-
cursor = conn.cursor()
|
43 |
-
cursor.execute("SELECT id, mots_cle FROM code")
|
44 |
-
rows = cursor.fetchall()
|
45 |
-
conn.close()
|
46 |
-
return [{"id" : v[0], "mot_cle" : v[1].replace("\n","")} for v in rows]
|
47 |
-
|
48 |
-
def return_niveau():
|
49 |
-
conn = sqlite3.connect("code.db")
|
50 |
-
cursor = conn.cursor()
|
51 |
-
cursor.execute("SELECT id, niveau FROM code")
|
52 |
-
rows = cursor.fetchall()
|
53 |
-
conn.close()
|
54 |
-
return [{"id" : v[0], "niveau" : v[1]} for v in rows]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|