2
0

redirect_pas.py 937 B

123456789101112131415161718192021222324
  1. import re
  2. from urllib import parse
  3. def url_pas(data):
  4. return parse.quote(data).replace('/','%2F')
  5. def redirect_pas(data, title, backlink):
  6. d_re = re.findall('\r\n#(?:redirect|넘겨주기) ((?:(?!\r|\n|%0D).)+)', data)
  7. for d in d_re:
  8. view = d.replace('\\', '')
  9. sh = ''
  10. s_d = re.search('#((?:(?!x27;|#).)+)$', d)
  11. if s_d:
  12. href = re.sub('#((?:(?!x27;|#).)+)$', '', d)
  13. sh = '#' + s_d.groups()[0]
  14. else:
  15. href = d
  16. a = href.replace('&#x27;', "'").replace('&quot;', '"').replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\')
  17. backlink += [[title, a, 'redirect']]
  18. data = re.sub('\r\n#(?:redirect|넘겨주기) ((?:(?!\r|\n|%0D).)+)', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(a) + '?froms=' + url_pas(title) + sh + '" />', data, 1)
  19. return [data, backlink]