mark.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from set_mark.namu import namu
  2. import re
  3. import html
  4. import sqlite3
  5. from urllib import parse
  6. import time
  7. import threading
  8. def load_conn2(data):
  9. global conn
  10. global curs
  11. conn = data
  12. curs = conn.cursor()
  13. def send_parser(data):
  14. if not re.search('^<br>$', data):
  15. data = html.escape(data)
  16. javascript = re.compile('javascript:', re.I)
  17. data = javascript.sub('', data)
  18. data = re.sub('&lt;a href=&quot;(?:(?:(?!&quot;).)*)&quot;&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + parse.quote('\g<in>').replace('/','%2F') + '">\g<in></a>', data)
  19. return data
  20. def plusing(name, link, backtype):
  21. curs.execute("select title from back where title = ? and link = ? and type = ?", [link, name, backtype])
  22. if not curs.fetchall():
  23. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  24. def namumark(title = '', data = '', num = 0):
  25. if not data == '':
  26. data = namu(conn, data, title, num)
  27. if num == 1:
  28. i = 0
  29. while 1:
  30. try:
  31. _ = data[2][i][0]
  32. except:
  33. break
  34. thread_start = threading.Thread(target = plusing, args = [data[2][i][0], data[2][i][1], data[2][i][2]])
  35. thread_start.start()
  36. thread_start.join()
  37. i += 1
  38. conn.commit()
  39. return data[0] + data[1]
  40. else:
  41. return '404 Not Found.'