mark.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. from bottle import request, app
  2. from bottle.ext import beaker
  3. from urllib import parse
  4. import json
  5. import sqlite3
  6. import time
  7. import re
  8. import hashlib
  9. import html
  10. import datetime
  11. json_data = open('set.json').read()
  12. set_data = json.loads(json_data)
  13. conn = sqlite3.connect(set_data['db'] + '.db')
  14. curs = conn.cursor()
  15. session_opts = {
  16. 'session.type': 'file',
  17. 'session.data_dir': './app_session/',
  18. 'session.auto': 1
  19. }
  20. app = beaker.middleware.SessionMiddleware(app(), session_opts)
  21. def get_time():
  22. now = time.localtime()
  23. date = "%04d-%02d-%02d %02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
  24. return(date)
  25. def ip_check():
  26. session = request.environ.get('beaker.session')
  27. if(session.get('Now') == 1):
  28. ip = format(session['DREAMER'])
  29. else:
  30. if(request.environ.get('HTTP_X_FORWARDED_FOR')):
  31. ip = request.environ.get('HTTP_X_FORWARDED_FOR')
  32. else:
  33. ip = request.environ.get('REMOTE_ADDR')
  34. return(ip)
  35. def url_pas(data):
  36. return(parse.quote(data).replace('/','%2F'))
  37. def sha224(data):
  38. return(hashlib.sha224(bytes(data, 'utf-8')).hexdigest())
  39. def savemark(data):
  40. data = re.sub("\[date\(now\)\]", get_time(), data)
  41. if(not re.search("\.", ip_check())):
  42. name = '[[사용자:' + ip_check() + '|' + ip_check() + ']]'
  43. else:
  44. name = ip_check()
  45. data = re.sub("\[name\]", name, data)
  46. return(data)
  47. def send_p(d):
  48. d = html.escape(d)
  49. js_p = re.compile('javascript:', re.I)
  50. d = js_p.sub('', d)
  51. d = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + url_pas('\g<in>') + '">\g<in></a>', d)
  52. return(d)
  53. def table_p(d, d2):
  54. alltable = 'style="'
  55. celstyle = 'style="'
  56. rowstyle = 'style="'
  57. row = ''
  58. cel = ''
  59. table_w = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", d)
  60. table_h = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", d)
  61. table_a = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", d)
  62. if(table_w):
  63. alltable += 'width: ' + table_w.groups()[0] + ';'
  64. if(table_h):
  65. alltable += 'height: ' + table_h.groups()[0] + ';'
  66. if(table_a):
  67. if(table_a.groups()[0] == 'right'):
  68. alltable += 'float: right;'
  69. elif(table_a.groups()[0] == 'center'):
  70. alltable += 'margin: auto;'
  71. table_t_a = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  72. if(table_t_a):
  73. if(table_t_a.groups()[0] == 'right'):
  74. alltable += 'text-align: right;'
  75. elif(table_t_a.groups()[0] == 'center'):
  76. alltable += 'text-align: center;'
  77. row_t_a = re.search("&lt;row\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  78. if(row_t_a):
  79. if(row_t_a.groups()[0] == 'right'):
  80. rowstyle += 'text-align: right;'
  81. elif(row_t_a.groups()[0] == 'center'):
  82. rowstyle += 'text-align: center;'
  83. else:
  84. rowstyle += 'text-align: left;'
  85. table_cel = re.search("&lt;-((?:(?!&gt;).)*)&gt;", d)
  86. if(table_cel):
  87. cel = 'colspan="' + table_cel.groups()[0] + '"'
  88. else:
  89. cel = 'colspan="' + str(round(len(d2) / 2)) + '"'
  90. table_row = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", d)
  91. if(table_row):
  92. row = 'rowspan="' + table_row.groups()[0] + '"'
  93. row_bgcolor_2 = re.search("&lt;rowbgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  94. row_bgcolor_3 = re.search("&lt;rowbgcolor=(\w+)&gt;", d)
  95. if(row_bgcolor_2):
  96. rowstyle += 'background: ' + row_bgcolor_2.groups()[0] + ';'
  97. elif(row_bgcolor_3):
  98. rowstyle += 'background: ' + row_bgcolor_3.groups()[0] + ';'
  99. table_border_2 = re.search("&lt;table\s?bordercolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  100. table_border_3 = re.search("&lt;table\s?bordercolor=(\w+)&gt;", d)
  101. if(table_border_2):
  102. alltable += 'border: ' + table_border_2.groups()[0] + ' 2px solid;'
  103. elif(table_border_3):
  104. alltable += 'border: ' + table_border_3.groups()[0] + ' 2px solid;'
  105. table_bgcolor_2 = re.search("&lt;table\s?bgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  106. table_bgcolor_3 = re.search("&lt;table\s?bgcolor=(\w+)&gt;", d)
  107. if(table_bgcolor_2):
  108. alltable += 'background: ' + table_bgcolor_2.groups()[0] + ';'
  109. elif(table_bgcolor_3):
  110. alltable += 'background: ' + table_bgcolor_3.groups()[0] + ';'
  111. bgcolor_2 = re.search("&lt;bgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  112. bgcolor_3 = re.search("&lt;bgcolor=(\w+)&gt;", d)
  113. if(bgcolor_2):
  114. celstyle += 'background: ' + bgcolor_2.groups()[0] + ';'
  115. elif(bgcolor_3):
  116. celstyle += 'background: ' + bgcolor_3.groups()[0] + ';'
  117. st_bgcolor_2 = re.search("&lt;(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  118. st_bgcolor_3 = re.search("&lt;(\w+)&gt;", d)
  119. if(st_bgcolor_2):
  120. celstyle += 'background: ' + st_bgcolor_2.groups()[0] + ';'
  121. elif(st_bgcolor_3):
  122. celstyle += 'background: ' + st_bgcolor_3.groups()[0] + ';'
  123. n_width = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", d)
  124. n_height = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", d)
  125. if(n_width):
  126. celstyle += 'width: ' + n_width.groups()[0] + ';'
  127. if(n_height):
  128. celstyle += 'height: ' + n_height.groups()[0] + ';'
  129. text_right = re.search("&lt;\)&gt;", d)
  130. text_center = re.search("&lt;:&gt;", d)
  131. text_left = re.search("&lt;\(&gt;", d)
  132. if(text_right):
  133. celstyle += 'text-align: right;'
  134. elif(text_center):
  135. celstyle += 'text-align: center;'
  136. elif(text_left):
  137. celstyle += 'text-align: left;'
  138. alltable += '"'
  139. celstyle += '"'
  140. rowstyle += '"'
  141. return([alltable, rowstyle, celstyle, row, cel])
  142. def html_pas(data):
  143. data = re.sub('%H%', '<', data)
  144. data = re.sub('%\/H%', '>', data)
  145. d_list = re.findall('<(\/)?([^> ]+)( (?:[^>]+)?)?>', data)
  146. for i_list in d_list:
  147. if(i_list[0] == ''):
  148. if(i_list[1] in ['div', 'span', 'embed', 'iframe']):
  149. if(re.search('<\/' + i_list[1] + '>', data)):
  150. src = re.search('src=([^ ]*)', i_list[2])
  151. if(src):
  152. v_src = re.search('https:\/\/([^/\'" ]*)', src.groups()[0])
  153. if(v_src):
  154. if(not v_src.groups()[0] in ["www.youtube.com", "serviceapi.nmv.naver.com", "tv.kakao.com", "www.google.com"]):
  155. ot = re.sub('src=([^ ]*)', '', i_list[2])
  156. else:
  157. ot = i_list[2]
  158. else:
  159. ot = re.sub('src=([^ ]*)', '', i_list[2])
  160. else:
  161. ot = i_list[2]
  162. po = re.compile('position', re.I)
  163. data = re.sub('<(\/)?([^> ]+)( (?:[^>]+)?)?>', '%H%' + i_list[1] + po.sub('', ot) + '%/H%', data, 1)
  164. data = re.sub('<\/' + i_list[1] + '>', '%H%/' + i_list[1] + '%/H%', data, 1)
  165. data = html.escape(data)
  166. end = re.findall('%H%((?:(?!%/H%).)*)%/H%', data)
  167. for d_end in end:
  168. data = re.sub('%H%((?:(?!%/H%).)*)%/H%', '<' + re.sub('&quot;', '"', re.sub('&#x27;', "'", d_end)) + '>', data, 1)
  169. return(data)
  170. def mid_pas(data, fol_num, include, in_c):
  171. com = re.compile("{{{((?:(?!{{{|}}}).)*)}}}", re.DOTALL)
  172. while(1):
  173. is_it = com.search(data)
  174. if(is_it):
  175. it_d = is_it.groups()[0]
  176. big_a = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  177. big = big_a.search(it_d)
  178. small_a = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  179. small = small_a.search(it_d)
  180. color_b = re.compile("^(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))\s(.*)$", re.DOTALL)
  181. color_2 = color_b.search(it_d)
  182. color_c = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  183. color_3 = color_c.search(it_d)
  184. back_a = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  185. back = back_a.search(it_d)
  186. back_b = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  187. back_2 = back_b.search(it_d)
  188. back_c = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  189. back_3 = back_c.search(it_d)
  190. include_out_a = re.compile("^#!noin\s(.*)$", re.DOTALL)
  191. include_out = include_out_a.search(it_d)
  192. div_a = re.compile("^#!wiki\sstyle=(?:&quot;|&#x27;)((?:(?!&quot;|&#x27;).)*)(?:&quot;|&#x27;)\r\n(.*)$", re.DOTALL)
  193. div = div_a.search(it_d)
  194. html_a = re.compile("^#!html\s(.*)$", re.DOTALL)
  195. html = html_a.search(it_d)
  196. fol_a = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
  197. fol = fol_a.search(it_d)
  198. syn_a = re.compile("^#!syntax\s([^\n]*)\r\n(.*)$", re.DOTALL)
  199. syn = syn_a.search(it_d)
  200. if(big):
  201. big_d = big.groups()
  202. data = com.sub('<span style="font-size: ' + str(int(big_d[0]) * 20 + 100) + '%;">' + big_d[1] + '</span>', data, 1)
  203. elif(small):
  204. sm_d = small.groups()
  205. data = com.sub('<span style="font-size: ' + str(100 - int(sm_d[0]) * 10) + '%;">' + sm_d[1] + '</span>', data, 1)
  206. elif(color_2):
  207. c_d_2 = color_2.groups()
  208. data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
  209. elif(color_3):
  210. c_d_3 = color_3.groups()
  211. data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
  212. elif(back):
  213. back_d_1 = back.groups()
  214. data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
  215. elif(back_2):
  216. back_d_2 = back_2.groups()
  217. data = com.sub('<span style="background: #' + back_d_2[0] + '">' + back_d_2[1] + '</span>', data, 1)
  218. elif(back_3):
  219. back_d_3 = back_3.groups()
  220. data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
  221. elif(div):
  222. div_d = div.groups()
  223. data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
  224. elif(html):
  225. data = com.sub(html.groups()[0], data, 1)
  226. elif(fol):
  227. fol_d = fol.groups()
  228. data = com.sub( "<div> \
  229. " + fol_d[0] + " \
  230. <div id='folding_" + str(fol_num + 1) + "' style='display: inline-block;'> \
  231. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>] \
  232. </div> \
  233. <div id='folding_" + str(fol_num + 2) + "' style='display: none;'> \
  234. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>접기</a>] \
  235. </div> \
  236. <div id='folding_" + str(fol_num) + "' style='display: none;'> \
  237. <br> \
  238. " + fol_d[1] + " \
  239. </div> \
  240. </div>", data, 1)
  241. fol_num += 3
  242. elif(syn):
  243. syn_d = syn.groups()
  244. data = com.sub('<pre id="syntax"><code class="' + syn_d[0] + '">' + re.sub('\r\n', '<isbr>', re.sub(' ', '<space>', syn_d[1])) + '</code></pre>', data, 1)
  245. elif(include_out):
  246. if((include or in_c) == 1):
  247. data = com.sub("", data, 1)
  248. else:
  249. data = com.sub(include_out.groups()[0], data, 1)
  250. else:
  251. data = com.sub('<code>' + it_d + '</code>', data, 1)
  252. else:
  253. break
  254. com = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
  255. da_com = com.findall(data)
  256. for com_da in da_com:
  257. mid_data = re.sub("<\/span>", "}}}", com_da)
  258. mid_data = re.sub("<\/div>", "}}}", mid_data)
  259. mid_data = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", mid_data)
  260. mid_data = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", mid_data)
  261. mid_data = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", mid_data)
  262. mid_data = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", mid_data)
  263. mid_data = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=\"\g<in>\"\n", mid_data)
  264. mid_data = mid_data.replace('<', '&lt;').replace('>', '&gt;')
  265. mid_data = re.sub("(?P<in>.)", "<nowiki>\g<in></nowiki>", mid_data)
  266. data = com.sub(mid_data, data, 1)
  267. return([data, fol_num])
  268. def toc_pas(data, title, num):
  269. i = [0, 0, 0, 0, 0, 0, 0]
  270. last = 0
  271. toc_c = -1
  272. toc_d = -1
  273. span = ''
  274. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  275. while(1):
  276. i[0] += 1
  277. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\r\n', data)
  278. if(m):
  279. result = m.groups()
  280. wiki = len(result[0])
  281. if(last < wiki):
  282. last = wiki
  283. else:
  284. last = wiki
  285. if(wiki == 1):
  286. i[2] = 0
  287. i[3] = 0
  288. i[4] = 0
  289. i[5] = 0
  290. i[6] = 0
  291. elif(wiki == 2):
  292. i[3] = 0
  293. i[4] = 0
  294. i[5] = 0
  295. i[6] = 0
  296. elif(wiki == 3):
  297. i[4] = 0
  298. i[5] = 0
  299. i[6] = 0
  300. elif(wiki == 4):
  301. i[5] = 0
  302. i[6] = 0
  303. elif(wiki == 5):
  304. i[6] = 0
  305. if(wiki == 1):
  306. i[1] += 1
  307. elif(wiki == 2):
  308. i[2] += 1
  309. elif(wiki == 3):
  310. i[3] += 1
  311. elif(wiki == 4):
  312. i[4] += 1
  313. elif(wiki == 5):
  314. i[5] += 1
  315. else:
  316. i[6] += 1
  317. toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
  318. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  319. toc = re.sub("0\.", '', toc)
  320. toc = re.sub("#\.", '.', toc)
  321. toc = re.sub("\.$", '', toc)
  322. if(toc_c == -1):
  323. margin = 'style="margin-top: 30px;"'
  324. toc_c = toc.count('.')
  325. else:
  326. toc_d = toc.count('.')
  327. if(toc_c == toc_d):
  328. margin = 'style="margin-top: 30px;"'
  329. else:
  330. if(toc_d < toc_c):
  331. margin = 'style="margin-top: 30px;"'
  332. else:
  333. margin = ''
  334. toc_c = toc_d
  335. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  336. if(test):
  337. g = test.groups()
  338. if(g[4]):
  339. span = '<span style="margin-left: 5px;"></span>' * 4
  340. elif(g[3]):
  341. span = '<span style="margin-left: 5px;"></span>' * 3
  342. elif(g[2]):
  343. span = '<span style="margin-left: 5px;"></span>' * 2
  344. elif(g[1]):
  345. span = '<span style="margin-left: 5px;"></span>'
  346. else:
  347. span = ''
  348. rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  349. c = re.sub(" $", "", result[1])
  350. d = c
  351. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  352. edit_d = ''
  353. if(num != 0):
  354. edit_d = ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span>'
  355. data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<tablenobr><h' + str(wiki) + ' id="' + c + '" ' + margin + '><a href="#toc" id="s-' + toc + '">' + toc + '.<span style="margin-left: 5px;"></span></a> ' + d + edit_d + '</h' + str(wiki) + '><hr style="margin-top: -5px;">', data, 1)
  356. else:
  357. rtoc += '</div>'
  358. break
  359. data = re.sub("\[목차\]", rtoc, data)
  360. return(data)
  361. def backlink_plus(name, link, backtype, num):
  362. if(num == 1):
  363. curs.execute("delete from back where title = ? and link = ? and type = ?", [link, name, backtype])
  364. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  365. def cat_plus(name, link, num):
  366. if(num == 1):
  367. curs.execute("delete from cat where title = ? and cat = ?", [link, name])
  368. curs.execute("insert into cat (title, cat) values (?, ?)", [link, name])
  369. def namumark(title, data, num, in_c):
  370. data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", data))
  371. data = html_pas(data)
  372. data = '\r\n' + data + '\r\n'
  373. fol_num = 0
  374. var_d = mid_pas(data, fol_num, 0, in_c)
  375. data = var_d[0]
  376. fol_num = var_d[1]
  377. include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:(?:,\s?(?:(?!\)\]).)*))+)?\)\]")
  378. while(1):
  379. m = include.search(data)
  380. if(m):
  381. results = m.groups()
  382. if(results[0] == title):
  383. data = include.sub("<b>" + results[0] + "</b>", data, 1)
  384. else:
  385. curs.execute("select data from data where title = ?", [results[0]])
  386. in_con = curs.fetchall()
  387. backlink_plus(title, results[0], 'include', num)
  388. if(in_con):
  389. in_data = in_con[0][0]
  390. in_data = include.sub("", in_data)
  391. in_data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", in_data))
  392. in_data = html_pas(in_data)
  393. var_d = mid_pas(in_data, fol_num, 1, in_c)
  394. in_data = var_d[0]
  395. fol_num = var_d[1]
  396. if(results[1]):
  397. a = results[1]
  398. while(1):
  399. g = re.search("([^= ,]*)\=([^,]*)", a)
  400. if(g):
  401. result = g.groups()
  402. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  403. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  404. else:
  405. break
  406. in_data = toc_pas(in_data, results[0], num)
  407. data = include.sub('\n<nobr><a href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><div>' + in_data + '</div><nobr>\n', data, 1)
  408. else:
  409. data = include.sub("<a class=\"not_thing\" href=\"/w/" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  410. else:
  411. break
  412. data = re.sub("\r\n##\s?([^\n]*)\r\n", "\r\n", data)
  413. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  414. data = savemark(data)
  415. while(1):
  416. r_data = re.search('\n#(?:redirect|넘겨주기) ([^\n]*)', data)
  417. if(r_data):
  418. n_data = r_data.groups()
  419. n_s_data = re.sub("\\\#", "<sharp>", n_data[0])
  420. s_data = re.search("^([^\n#]*)(#(?:[^\n]*))?$", n_s_data)
  421. r_s_data = s_data.groups()
  422. n_sharp = re.sub("<sharp>", "#", r_s_data[0])
  423. if(r_s_data[1]):
  424. plus = r_s_data[1]
  425. else:
  426. plus = ''
  427. data = re.sub('\n#(?:redirect|넘겨주기) ([^\n]*)', '<meta http-equiv="refresh" content="0;url=/w/' + re.sub('%0D$', '', url_pas(n_sharp)) + '/from/' + url_pas(title) + plus + '" />', data, 1)
  428. backlink_plus(title, n_data[0], 'redirect', num)
  429. else:
  430. break
  431. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  432. while(1):
  433. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  434. if(m):
  435. result = m.groups()
  436. blockquote = result[0]
  437. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  438. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  439. else:
  440. break
  441. if(not re.search('\[목차\]', data)):
  442. if(not re.search('\[목차\(없음\)\]', data)):
  443. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  444. else:
  445. data = re.sub("\[목차\(없음\)\]", "", data)
  446. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  447. data = toc_pas(data, title, num)
  448. category = ''
  449. while(1):
  450. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  451. if(m):
  452. g = m.groups()
  453. if(title != g[0]):
  454. cat_plus(title, g[0], num)
  455. if(category == ''):
  456. curs.execute("select title from data where title = ?", [g[0]])
  457. exists = curs.fetchall()
  458. if(exists):
  459. red = ""
  460. else:
  461. red = 'class="not_thing"'
  462. category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  463. else:
  464. curs.execute("select title from data where title = ?", [g[0]])
  465. exists = curs.fetchall()
  466. if(exists):
  467. red = ""
  468. else:
  469. red = 'class="not_thing"'
  470. category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  471. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  472. else:
  473. break
  474. data = re.sub("&#x27;&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;&#x27;).)*)&#x27;&#x27;&#x27;", '<b>\g<in></b>', data)
  475. data = re.sub("&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;).)*)&#x27;&#x27;", '<i>\g<in></i>', data)
  476. data = re.sub('(?:~~|--)(?P<in>(?:(?!~~|--).)+)(?:~~|--)', '<s>\g<in></s>', data)
  477. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  478. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  479. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  480. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  481. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table> \
  482. <tbody> \
  483. <tr> \
  484. <td> \
  485. \g<in> \
  486. </td> \
  487. </tr> \
  488. </tbody> \
  489. </table>', data)
  490. data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby> \
  491. \g<in> \
  492. <rp>(</rp> \
  493. <rt>\g<out></rt> \
  494. <rp>)</rp> \
  495. </ruby>', data)
  496. test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
  497. if(test):
  498. for wiki in test:
  499. if(wiki[1]):
  500. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[1] + '</a>', data, 1)
  501. else:
  502. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[0] + '</a>', data, 1)
  503. data = re.sub("\[br\]",'<br>', data)
  504. while(1):
  505. com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
  506. m = com.search(data)
  507. if(m):
  508. src = ''
  509. width = '560'
  510. height = '315'
  511. time = '0'
  512. result = m.groups()
  513. if(result[0]):
  514. yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-_]*))$', result[0])
  515. if(yudt):
  516. if(yudt.groups()[0]):
  517. src = yudt.groups()[0]
  518. elif(yudt.groups()[1]):
  519. src = yudt.groups()[1]
  520. elif(yudt.groups()[2]):
  521. src = yudt.groups()[2]
  522. else:
  523. src = ''
  524. if(result[1]):
  525. mdata = re.search('width=([0-9%]*)', result[1])
  526. if(mdata):
  527. width = mdata.groups()[0]
  528. mdata = re.search('height=([0-9%]*)', result[1])
  529. if(mdata):
  530. height = mdata.groups()[0]
  531. mdata = re.search('time=([0-9]*)', result[1])
  532. if(mdata):
  533. time = mdata.groups()[0]
  534. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  535. else:
  536. break
  537. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  538. a = re.findall('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', data)
  539. for i in a:
  540. b = re.search('(.*)\/', title)
  541. if(b):
  542. m = b.groups()
  543. if(i):
  544. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + i + ']]', data, 1)
  545. else:
  546. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + ']]', data, 1)
  547. else:
  548. if(i):
  549. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + i + ']]', data, 1)
  550. else:
  551. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + ']]', data, 1)
  552. data = re.sub('\[\[(?P<in>\/[^\]|]*)(?P<out>\|(?:[^\]]*))?\]\]', '[[' + title + '\g<in>\g<out>]]', data)
  553. link = re.compile('\[\[((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]')
  554. d_da = link.findall(data)
  555. for d in d_da:
  556. if(re.search('^(?:파일|외부):', d[0])):
  557. width = ''
  558. height = ''
  559. align = ''
  560. try:
  561. w_d = re.search('width=([0-9]+(?:[a-z%]+)?)', d[1])
  562. if(w_d):
  563. width = 'width="' + w_d.groups()[0] + '" '
  564. h_d = re.search('height=([0-9]+(?:[a-z%]+)?)', d[1])
  565. if(h_d):
  566. height = 'height="' + h_d.groups()[0] + '" '
  567. a_d = re.search('align=(left|center|right)', d[1])
  568. if(a_d):
  569. align = 'text-align: ' + a_d.groups()[0] + ';'
  570. except:
  571. pass
  572. f_d = re.search('^파일:([^.]+)\.(.+)$', d[0])
  573. if(f_d):
  574. if(not re.search("^파일:([^\n]*)", title)):
  575. backlink_plus(title, d[0], 'file', num)
  576. img = '<span style="display: block; ' + align + '"><img src="/image/' + sha224(f_d.groups()[0]) + '.' + f_d.groups()[1] + '" ' + width + height + '></span>'
  577. data = link.sub(img, data, 1)
  578. else:
  579. img = '<span style="display: block; ' + align + '"><img src="' + re.sub('^외부:', '', d[0]) + '" ' + width + height + '></span>'
  580. data = link.sub(img, data, 1)
  581. elif(re.search('^https?:\/\/', d[0])):
  582. view = d[0]
  583. try:
  584. if(re.search('(.+)', d[1])):
  585. view = d[1]
  586. except:
  587. pass
  588. data = link.sub('<a class="out_link" rel="nofollow" href="' + d[0] + '">' + view + '</a>', data, 1)
  589. else:
  590. view = d[0].replace('\\', '')
  591. try:
  592. if(re.search('(.+)', d[1])):
  593. view = d[1]
  594. except:
  595. pass
  596. sh = ''
  597. s_d = re.search('#([^#]+)$', d[0])
  598. if(s_d):
  599. href = re.sub('#([^#]+)$', '', d[0])
  600. sh = '#' + s_d.groups()[0]
  601. else:
  602. href = d[0]
  603. if(d[0] == title):
  604. data = link.sub('<b>' + view + '</b>', data, 1)
  605. elif(re.search('^#', d[0])):
  606. data = link.sub('<a href="' + url_pas(href.replace('\\', '')) + sh + '">' + view + '</a>', data, 1)
  607. else:
  608. backlink_plus(title, href.replace('\\', ''), '', num)
  609. curs.execute("select title from data where title = ?", [href.replace('\\', '')])
  610. if(not curs.fetchall()):
  611. no = 'class="not_thing"'
  612. else:
  613. no = ''
  614. data = link.sub('<a ' + no + ' href="/w/' + url_pas(href.replace('\\', '')) + sh + '">' + view + '</a>', data, 1)
  615. while(1):
  616. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  617. if(m):
  618. result = m.groups()
  619. end = str(result[0])
  620. while(1):
  621. isspace = re.search("( +)\*\s([^\n]*)", end)
  622. if(isspace):
  623. spacebar = isspace.groups()
  624. up = len(spacebar[0]) * 20
  625. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  626. else:
  627. break
  628. end = re.sub("\n", '', end)
  629. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul style="margin-top: 10px;" id="list">' + end + '</ul>', data, 1)
  630. else:
  631. break
  632. now_time = get_time()
  633. data = re.sub('\[date\]', now_time, data)
  634. time_data = re.search('^([0-9]{4}-[0-9]{2}-[0-9]{2})', now_time)
  635. time = time_data.groups()
  636. age_data = re.findall('\[age\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
  637. for age in age_data:
  638. old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
  639. will = datetime.datetime.strptime(age, '%Y-%m-%d')
  640. e_data = old - will
  641. data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(int(int(e_data.days) / 365)), data, 1)
  642. dday_data = re.findall('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
  643. for dday in dday_data:
  644. old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
  645. will = datetime.datetime.strptime(dday, '%Y-%m-%d')
  646. e_data = old - will
  647. if(re.search('^-', str(e_data.days))):
  648. e_day = str(e_data.days)
  649. else:
  650. e_day = '+' + str(e_data.days)
  651. data = re.sub('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', e_day, data, 1)
  652. data = re.sub("-{4,11}", "<hr>", data)
  653. while(1):
  654. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  655. if(b):
  656. result = b.groups()
  657. up = re.sub(' ', '<span id="in"></span>', result[1])
  658. if(re.search('<\/h[0-9]>', result[0])):
  659. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  660. else:
  661. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  662. else:
  663. break
  664. a = 1
  665. tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
  666. namu = []
  667. while(1):
  668. b = re.search("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", data)
  669. if(b):
  670. results = b.groups()
  671. if(not results[1] and results[0]):
  672. i = 0
  673. while(1):
  674. try:
  675. if(namu[i] == results[0]):
  676. none_this = 0
  677. break
  678. else:
  679. i += 2
  680. except:
  681. none_this = 1
  682. break
  683. if(none_this == 0):
  684. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  685. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  686. </sup> \
  687. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  688. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + namu[i + 1] + " \
  689. </div>", data, 1)
  690. else:
  691. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  692. <a href='javascript:void(0);' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  693. </sup>", data, 1)
  694. else:
  695. if(results[0]):
  696. namu += [results[0]]
  697. namu += [results[1]]
  698. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + results[0] + "]</a> " + results[1] + "</span><br>"
  699. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  700. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  701. </sup> \
  702. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  703. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + results[1] + " \
  704. </div>", data, 1)
  705. else:
  706. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + str(a) + "]</a> " + results[1] + "</span><br>"
  707. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", '<sup> \
  708. <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');" id="rfn-' + str(a) + '">[' + str(a) + ']</a> \
  709. </sup> \
  710. <div class="popup" style="display: none;" id="folding_' + str(fol_num) + '"> \
  711. <a onclick="folding(' + str(fol_num) + ');" href="#fn-' + str(a) + '">[' + str(a) + ']</a> <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');">[X]</a> ' + results[1] + ' \
  712. </div>', data, 1)
  713. a += 1
  714. fol_num += 2
  715. else:
  716. tou += '</div>'
  717. if(tou == "<hr style='margin-top: 30px;' id='footnote'><div><br></div>"):
  718. tou = ""
  719. break
  720. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  721. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  722. data = re.sub("\[각주\]", "<br>" + tou, data)
  723. data += tou
  724. if(category):
  725. data += '<div style="margin-top: 30px;" id="cate">분류: ' + category + '</div>'
  726. data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
  727. while(1):
  728. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  729. if(y):
  730. a = y.groups()
  731. mid_data = re.sub("\|\|", "#table#", a[0])
  732. mid_data = re.sub("\r\n", "<br>", mid_data)
  733. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  734. else:
  735. break
  736. data = re.sub("#table#", "||", data)
  737. data = re.sub("<tablenobr>", "\r\n", data)
  738. while(1):
  739. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  740. if(m):
  741. results = m.groups()
  742. table = results[0]
  743. while(1):
  744. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  745. if(a):
  746. row = ''
  747. cel = ''
  748. celstyle = ''
  749. rowstyle = ''
  750. alltable = ''
  751. table_d = ''
  752. result = a.groups()
  753. if(result[1]):
  754. table_d = table_p(result[1], result[0])
  755. alltable = table_d[0]
  756. rowstyle = table_d[1]
  757. celstyle = table_d[2]
  758. row = table_d[3]
  759. cel = table_d[4]
  760. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "> \
  761. <tbody> \
  762. <tr " + rowstyle + "> \
  763. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  764. else:
  765. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  766. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table> \
  767. <tbody> \
  768. <tr> \
  769. <td " + cel + ">", table, 1)
  770. else:
  771. break
  772. table = re.sub("\|\|$", "</td> \
  773. </tr> \
  774. </tbody> \
  775. </table>", table)
  776. while(1):
  777. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  778. if(b):
  779. row = ''
  780. cel = ''
  781. celstyle = ''
  782. rowstyle = ''
  783. table_d = ''
  784. result = b.groups()
  785. if(result[1]):
  786. table_d = table_p(result[1], result[0])
  787. rowstyle = table_d[1]
  788. celstyle = table_d[2]
  789. row = table_d[3]
  790. cel = table_d[4]
  791. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  792. </tr> \
  793. <tr " + rowstyle + "> \
  794. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  795. else:
  796. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  797. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  798. </tr> \
  799. <tr> \
  800. <td " + cel + ">", table, 1)
  801. else:
  802. break
  803. while(1):
  804. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  805. if(c):
  806. row = ''
  807. cel = ''
  808. celstyle = ''
  809. table_d = ''
  810. result = c.groups()
  811. if(result[1]):
  812. table_d = table_p(result[1], result[0])
  813. celstyle = table_d[2]
  814. row = table_d[3]
  815. cel = table_d[4]
  816. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  817. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  818. else:
  819. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  820. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  821. <td " + cel + ">", table, 1)
  822. else:
  823. break
  824. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  825. else:
  826. break
  827. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  828. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  829. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  830. data = re.sub("<space>", " ", data)
  831. data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
  832. data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
  833. data = re.sub('\n', '<br>', data)
  834. data = re.sub('<isbr>', '\r\n', data)
  835. data = re.sub('^(?:<br>|\r|\n| )+', '', data)
  836. data = re.sub('^<div style="margin-top: 30px;" id="cate">', '<div id="cate">', data)
  837. conn.commit()
  838. return(data)