dav74 commited on
Commit
1dab085
·
verified ·
1 Parent(s): 9401176

Delete database.py

Browse files
Files changed (1) hide show
  1. database.py +0 -42
database.py DELETED
@@ -1,42 +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 == 3 :
16
- tab = txt.split(";;;\n")
17
- txt = ""
18
- c = 0
19
- cursor.execute("INSERT INTO code (id, titre, enonce, test)VALUES (?, ?, ?, ?)", (id, tab[0], tab[1], tab[2]))
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 FROM code")
28
- rows = cursor.fetchall()
29
- conn.close()
30
- return [{"id" : v[0], "title" : v[1].replace("\n","")} for v in rows]
31
-
32
-
33
-
34
- def return_exercise(id):
35
- conn = sqlite3.connect("code.db")
36
- cursor = conn.cursor()
37
- cursor.execute("SELECT * FROM code WHERE id = ?", (id,))
38
- rows = cursor.fetchall()
39
- return rows[0]
40
-
41
-
42
- create_table()