mark.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from .set_mark.namumark import namumark, link_fix
  2. from .set_mark.tool import *
  3. import re
  4. import html
  5. import sqlite3
  6. import asyncio
  7. import threading
  8. import urllib.parse
  9. import multiprocessing
  10. def load_conn2(data):
  11. global conn
  12. global curs
  13. conn = data
  14. curs = conn.cursor()
  15. def send_parser(data):
  16. if not re.search('^<br>$', data):
  17. data = html.escape(data)
  18. data = re.sub('javascript:', '', data, flags = re.I)
  19. data = data.replace('&lt;br&gt;', '')
  20. link_re = re.compile('&lt;a(?: (?:(?:(?!&gt;).)*))?&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;')
  21. link_data = link_re.findall(data)
  22. for i in link_data:
  23. data = link_re.sub('<a href="/w/' + urllib.parse.quote(i).replace('/','%2F') + '">' + i + '</a>', data, 1)
  24. return data
  25. def render_do(title, data, num, include):
  26. if num == 3:
  27. num = 1
  28. back_num = 3
  29. else:
  30. back_num = num
  31. curs.execute(db_change('select data from other where name = "markup"'))
  32. rep_data = curs.fetchall()
  33. if rep_data[0][0] == 'namumark':
  34. data = namumark(conn, data, title, num, include)
  35. elif rep_data[0][0] == 'raw':
  36. data = [data, '', []]
  37. else:
  38. data = ['', '', []]
  39. if num == 1:
  40. if data[2] == []:
  41. curs.execute(db_change("insert into back (title, link, type) values ('test', ?, 'nothing')"), [title])
  42. else:
  43. curs.executemany(db_change("insert into back (link, title, type) values (?, ?, ?)"), data[2])
  44. curs.execute(db_change("delete from back where title = ? and type = 'no'"), [title])
  45. if back_num != 3:
  46. conn.commit()
  47. if num == 2:
  48. return [data[0], data[1]]
  49. else:
  50. return data[0] + '<script>' + data[1] + '</script>'