mark.py 43 KB

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