2
0

mark.py 43 KB

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