Python web board system (textboard, CGI, flatfile) http://4x13.net/bbs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

32 lines
766 B

  1. import os
  2. import re
  3. from collections import defaultdict
  4. import webtools as wt
  5. threadpath = "./threads/"
  6. def load_thread(th):
  7. th = int(th)
  8. thp = str(threadpath + str(th) + '.txt')
  9. if not os.path.exists(thp):
  10. return None
  11. with open(thp, 'r') as mt:
  12. mt = mt.read().splitlines()
  13. return mt
  14. def do_backlink(th='0'):
  15. mt = load_thread(th)
  16. bld = defaultdict(list)
  17. for n, t in enumerate(mt):
  18. repl = re.findall(r'\>\>[1-9][00-99]*', t)
  19. repl = [r[8:] for r in repl if r]
  20. for r in repl:
  21. if int(r) >= len(mt) or str(n) in bld[r]:
  22. continue
  23. bld[r].append(str(n))
  24. for r in sorted([int(k) for k in bld.keys()]):
  25. r = str(r)
  26. return bld