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.
 
 
 
 
 

108 lines
3.2 KiB

  1. #!/usr/bin/env python3
  2. import os
  3. thread_dir = "./threads/"
  4. with open("list.txt", "r") as lis:
  5. lis = lis.read().splitlines()
  6. with open("ips.txt", "r") as ips:
  7. ips = ips.read().splitlines()
  8. with open("ips2.txt", "r") as ips2:
  9. ips2 = ips2.read().splitlines()
  10. def menu():
  11. # delete a thread, moderate a post, or moderate a thread
  12. modes = ["del_thread", "mod_post", "mod_thread"]
  13. for n, i in enumerate(modes):
  14. print(n+1, " - ", i)
  15. pic_mode = input("Pick a mode.\n")
  16. if modes[int(pic_mode) -1]:
  17. m_mod = modes[int(pic_mode) -1]
  18. print(m_mod)
  19. thr = input("Thread to load:\n> ")
  20. eval(str(m_mod + "(" + thr + ")"))
  21. def mod_thread(thr=''):
  22. # open a thread, pick a mode [0-4], then write thread
  23. # and update list
  24. modes = ["normal", "lock", "sticky", "stickylock", "nobump"]
  25. tmod = -1
  26. thr = str(thr)
  27. with open(thread_dir + thr + ".txt") as tth:
  28. tth = tth.read().splitlines()
  29. if len(tth[0].split("><")) > 1:
  30. tmod = int(tth[0].split("><")[1])
  31. if tmod > 0:
  32. print("Thread is currently", modes[tmod])
  33. for n, i in enumerate(modes):
  34. modes[n] = str(n) + " ~ " + i
  35. print("New mode?\n *", "\n * ".join(modes))
  36. nmod = input("[0-4] ")
  37. tth[0] = tth[0].split(" >< ")[0] + " >< " + nmod
  38. print("\n".join(tth))
  39. with open(thread_dir + thr + ".txt", 'w') as th:
  40. th.write("\n".join(tth) + "\n")
  41. for n, i in enumerate(lis):
  42. if i.startswith(thr):
  43. i = i[:-1]
  44. i += str(nmod)
  45. lis[n] = i
  46. with open("list.txt", "w") as listw:
  47. listw.write("\n".join(lis))
  48. def del_thread(thr=''):
  49. # thread_dir + thr + txt
  50. # delete it, then remove thr from list
  51. # confirm before writing
  52. thr = str(thr)
  53. if os.path.exists(thread_dir + thr + ".txt"):
  54. print(thread_dir + thr + ".txt")
  55. for n, line in enumerate(lis):
  56. if line.startswith(thr):
  57. print(n, line)
  58. magic = line.split(" >< ")
  59. print(magic)
  60. break
  61. doy = "Do you want to remove " + magic[2] + "?\n> "
  62. conf = input(doy)
  63. if conf.strip().lower()[0] is "y":
  64. lis.pop(n)
  65. liss = "\n".join(lis)
  66. with open("list.txt", "w") as lisss:
  67. lisss.write(liss)
  68. os.remove(thread_dir + thr + ".txt")
  69. def mod_post(thr):
  70. # either "r" (remove) or "w" (warn) a reply # in thread #
  71. thr = str(thr)
  72. with open(thread_dir + thr + ".txt", "r") as tthr:
  73. tthr = tthr.read().splitlines()
  74. pcnt = len(tthr) - 1
  75. pos = input(f"Post to Modify\n[1-{pcnt}] ")
  76. pos = int(pos)
  77. rw = input("Remove or warn?\n[r/w] ").strip()
  78. if 0 < pos < (len(tthr)):
  79. print(tthr[pos])
  80. if rw == "r":
  81. tthr[pos] = "- >< - >< >< <i>post removed by moderator</i>"
  82. elif rw == "w":
  83. tthr[pos] += "<br><br><b style='color:red'>(USER WAS BANNED FOR THIS POST)</b>"
  84. with open(thread_dir + thr + ".txt", "w") as thrt:
  85. thrt.write("\n".join(tthr) + "\n")
  86. else:
  87. print("Post not found:", (len(tthr) - 1),
  88. "vs", pos)
  89. def scan_badword():
  90. # grep -Hn string *
  91. # returns thread filename & linenum + 1
  92. print("h")
  93. if __name__ == "__main__":
  94. menu()