coding utf8 import MySQLdb def app book chapter paragraph type db MySQ

 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
# -*- coding: utf8 -*-
import MySQLdb
def app(book,chapter,paragraph,type):
db = MySQLdb.connect(host = "127.0.0.1", user = "root", db = "physics", charset = 'utf8')
cursor = db.cursor()
if book[0]==0:
sql="INSERT INTO book (book_number,book_name,book_description,book_kw) VALUES ("+str(book[1])+",'"+book[2]+"','"+book[3]+"','"+book[4]+"');"
cursor.execute(sql)
db.commit()
sql="SELECT book_id FROM book WHERE book_number="+str(book[1])+";"
cursor.execute(sql)
a=cursor.fetchall()
book[0]=a[0][0]
if chapter[0]==0:
sql="INSERT INTO chapter (chapter_number,chapter_name,chapter_description,chapter_kw,book_id) VALUES ("+str(chapter[1])+",'"+chapter[2]+"','"+chapter[3]+"','"+chapter[4]+"',"+str(book[0])+");"
cursor.execute(sql)
db.commit()
sql="SELECT chapter_id FROM chapter WHERE chapter_number="+str(chapter[1])+" AND book_id="+str(book[0])+";"
cursor.execute(sql)
a=cursor.fetchall()
chapter=a[0][0]
if type==0:
sql="INSERT INTO paragraph (paragraph_number,paragraph_name,paragraph_description,paragraph_kw,paragraph_content,chapter_id) VALUES ("+str(paragraph[0])+",'"+paragraph[1]+"','"+paragraph[2]+"','"+paragraph[3]+"','"+paragraph[4]+"',"+str(chapter[0])+");"
else:
sql="INSERT INTO problem (problem_number,problem_name,problem_kw,problem_content,chapter_id) VALUES ("+str(paragraph[0])+",'"+paragraph[1]+"','"+paragraph[2]+"','"+paragraph[3]+"',"+str(chapter[0])+");"
cursor.execute(sql)
db.commit()
def append_prompt(prompt,paragraph):
if paragraph!=0:
sql="INSERT INTO prompt (prompt_number,prompt_name,prompt_kw,prompt_content,paragraph_id) VALUES ("+str(prompt[0])+",'"+prompt[1]+"','"+prompt[2]+"','"+prompt[3]+"',"+str(chapter[0])+str(paragraph)+");"
else:
sql="INSERT INTO prompt (prompt_number,prompt_name,prompt_kw,prompt_content) VALUES ("+str(prompt[0])+",'"+prompt[1]+"','"+prompt[2]+"','"+prompt[3]+"',"+str(chapter[0])+");"
cursor.execute(sql)
db.commit()
def correct(html):
f = open(html, "r")
l=f.readline()
rez=""
while l!="":
s = l.replace("\n","").replace("'",'"')
rez=rez+s
l=f.readline()
f.close()
return rez
def correct(html):
f = open(html, "r")
l=f.readline()
rez=""
while l!="":
s = l.replace("\n","").replace("'",'"').replace('img src="','img src="/static/image/')
rez=rez+s
l=f.readline()
f.close()
return rez
s=r"C:\ProjectDF\old\LyX\LyX\1 Vveden.xhtml"
app([0,1,"Книга 1","Описание книги 1","Ключевые слова к книге 1"],[0,1,"Глава 1","Описание главы 1","Ключевые слова главы 1"],[1,"Введение","Описание Параграфа 1.1","Ключевые слова Параграфа 1.1",correct(s)],0)