Advertisement
Guest User

lol

a guest
Oct 17th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.67 KB | None | 0 0
  1. from pychan import FourChan, LogLevel, PychanLogger
  2. from pychan.models import Thread
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.common.keys import Keys
  6. import time
  7. import random
  8. import os
  9.  
  10. ITTAN = 30
  11. IPPUN = 60
  12. NIFUN = 120
  13. GOFUN = 300
  14. JUPPUN = 600
  15. HANJIKAN = 1800
  16. ITIJIKAN = 3600
  17. BEG_DELAY = GOFUN
  18. BEG_DELAY_FACTOR = ITIJIKAN
  19. LAST_REPLYCOUNT = 0
  20. IMG_GENKAI_TOPPA = False
  21. jp_thread_no = 0
  22.  
  23. #AMELIA
  24. BAELZ = 0
  25. BIJOU = 1
  26. FAUNA = 2
  27. FWMC = 3
  28. GURA = 4
  29. INANIS = 5
  30. IRYS = 6
  31. KIARA = 7
  32. KRONII = 8
  33. MORI = 9
  34. MUMEI = 10
  35. NERISSA = 11
  36. SHIORI = 12
  37. CURRENT_MAX = 12
  38.  
  39. bigrange, smallrange = 200, 20
  40. vt_thread_numbers = [0 for a in range(smallrange)]
  41. img_totals = [0 for b in range(smallrange)]
  42. img_counts = [0 for c in range(smallrange)]
  43. img_lists = [[0 for d in range(bigrange)] for e in range(smallrange)]
  44.  
  45. ameliaimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\amelia"
  46. baelzimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\baelz"
  47. bijouimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\bijou"
  48. faunaimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\fauna"
  49. fwmcimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\fwmc"
  50. guraimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\gura"
  51. inanisimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\inanis"
  52. irysimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\irys"
  53. kiaraimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\kiara"
  54. kroniiimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\kronii"
  55. moriimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\mori"
  56. mumeiimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\mumei"
  57. nerissaimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\nerissa"
  58. shioriimgdirectory = "C:\\Users\\user\\PycharmProjects\\ENggarBot\\shiori"
  59.  
  60. img_directories = ([baelzimgdirectory, bijouimgdirectory, faunaimgdirectory, fwmcimgdirectory, guraimgdirectory,
  61. inanisimgdirectory, irysimgdirectory, kiaraimgdirectory, kroniiimgdirectory, moriimgdirectory,
  62. mumeiimgdirectory, nerissaimgdirectory, shioriimgdirectory])
  63.  
  64. #amelia's thread has no title because her fans are on another level of autism, separate loop in find_vt_threads
  65. baelz_thread_title = "/rrat/"
  66. bijou_thread_title = "/gem/"
  67. fauna_thread_title = "/uuu/"
  68. fwmc_thread_title = "/baubau/"
  69. gura_thread_title = "/ggg/"
  70. inanis_thread_title = "/wah/"
  71. irys_thread_title = "/HiRyS/"
  72. kiara_thread_title = "/wawa/"
  73. kronii_thread_title = "/∞/"
  74. mori_thread_title = "森カリオペ"
  75. mumei_thread_title = "/who/"
  76. nerissa_thread_title = "/ope/"
  77. shiori_thread_title = "Shiori Novella"
  78.  
  79. logger = PychanLogger(LogLevel.INFO)
  80. fourchan = FourChan(logger=logger, raise_http_exceptions=True, raise_parsing_exceptions=True)
  81. options = webdriver.ChromeOptions()
  82. options.add_argument("user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data")
  83. driver = webdriver.Chrome(options=options)
  84.  
  85.  
  86. def init_img_folders():
  87. #AMELIA
  88. img_lists[BAELZ] = os.listdir(baelzimgdirectory)
  89. img_totals[BAELZ] = len(img_lists[BAELZ])
  90. random.shuffle(img_lists[BAELZ])
  91. img_counts[BAELZ] = 0
  92. img_lists[BIJOU] = os.listdir(bijouimgdirectory)
  93. img_totals[BIJOU] = len(img_lists[BIJOU])
  94. random.shuffle(img_lists[BIJOU])
  95. img_counts[BIJOU] = 0
  96. img_lists[FAUNA] = os.listdir(faunaimgdirectory)
  97. img_totals[FAUNA] = len(img_lists[FAUNA])
  98. random.shuffle(img_lists[FAUNA])
  99. img_counts[FAUNA] = 0
  100. img_lists[FWMC] = os.listdir(fwmcimgdirectory)
  101. img_totals[FWMC] = len(img_lists[FWMC])
  102. random.shuffle(img_lists[FWMC])
  103. img_counts[FWMC] = 0
  104. img_lists[GURA] = os.listdir(guraimgdirectory)
  105. img_totals[GURA] = len(img_lists[GURA])
  106. random.shuffle(img_lists[GURA])
  107. img_counts[GURA] = 0
  108. img_lists[INANIS] = os.listdir(inanisimgdirectory)
  109. img_totals[INANIS] = len(img_lists[INANIS])
  110. random.shuffle(img_lists[INANIS])
  111. img_counts[INANIS] = 0
  112. img_lists[IRYS] = os.listdir(irysimgdirectory)
  113. img_totals[IRYS] = len(img_lists[IRYS])
  114. random.shuffle(img_lists[IRYS])
  115. img_counts[IRYS] = 0
  116. img_lists[KIARA] = os.listdir(kiaraimgdirectory)
  117. img_totals[KIARA] = len(img_lists[KIARA])
  118. random.shuffle(img_lists[KIARA])
  119. img_counts[KIARA] = 0
  120. img_lists[KRONII] = os.listdir(kroniiimgdirectory)
  121. img_totals[KRONII] = len(img_lists[KRONII])
  122. random.shuffle(img_lists[KRONII])
  123. img_counts[KRONII] = 0
  124. img_lists[MORI] = os.listdir(moriimgdirectory)
  125. img_totals[MORI] = len(img_lists[MORI])
  126. random.shuffle(img_lists[MORI])
  127. img_counts[MORI] = 0
  128. img_lists[MUMEI] = os.listdir(mumeiimgdirectory)
  129. img_totals[MUMEI] = len(img_lists[MUMEI])
  130. random.shuffle(img_lists[MUMEI])
  131. img_counts[MUMEI] = 0
  132. img_lists[NERISSA] = os.listdir(nerissaimgdirectory)
  133. img_totals[NERISSA] = len(img_lists[NERISSA])
  134. random.shuffle(img_lists[NERISSA])
  135. img_counts[NERISSA] = 0
  136. img_lists[SHIORI] = os.listdir(shioriimgdirectory)
  137. img_totals[SHIORI] = len(img_lists[SHIORI])
  138. random.shuffle(img_lists[SHIORI])
  139. img_counts[SHIORI] = 0
  140.  
  141.  
  142. def find_vt_threads():
  143. global vt_thread_numbers
  144. for g in range(smallrange):
  145. vt_thread_numbers[g] = 0
  146. for thread in fourchan.get_threads("vt"):
  147. threadtitle = str(thread.title)
  148. # get the amelia thread separately because her fans are turboautists that refuse to have a title
  149. #OP_post_no = int(thread.number)
  150. #for post in fourchan.get_posts(thread)
  151. # if (post.number == OP_post_no) and ("Amelia Watson appreciation" in post.text):
  152. # vt_thread_numbers[AMELIA] = thread.number
  153. if baelz_thread_title in threadtitle:
  154. vt_thread_numbers[BAELZ] = thread.number
  155. elif bijou_thread_title in threadtitle:
  156. vt_thread_numbers[BIJOU] = thread.number
  157. elif fauna_thread_title in threadtitle:
  158. vt_thread_numbers[FAUNA] = thread.number
  159. elif fwmc_thread_title in threadtitle:
  160. vt_thread_numbers[FWMC] = thread.number
  161. elif gura_thread_title in threadtitle:
  162. vt_thread_numbers[GURA] = thread.number
  163. elif inanis_thread_title in threadtitle:
  164. vt_thread_numbers[INANIS] = thread.number
  165. elif irys_thread_title in threadtitle:
  166. vt_thread_numbers[IRYS] = thread.number
  167. elif kiara_thread_title in threadtitle:
  168. vt_thread_numbers[KIARA] = thread.number
  169. elif kronii_thread_title in threadtitle:
  170. vt_thread_numbers[KRONII] = thread.number
  171. elif mori_thread_title in threadtitle:
  172. vt_thread_numbers[MORI] = thread.number
  173. elif mumei_thread_title in threadtitle:
  174. vt_thread_numbers[MUMEI] = thread.number
  175. elif nerissa_thread_title in threadtitle:
  176. vt_thread_numbers[NERISSA] = thread.number
  177. elif shiori_thread_title in threadtitle:
  178. vt_thread_numbers[SHIORI] = thread.number
  179.  
  180.  
  181. def find_jp_thread():
  182. global jp_thread_no, LAST_JP_THREADNO
  183. LAST_JP_THREADNO = jp_thread_no
  184. jp_thread_no = 0
  185. while jp_thread_no == 0:
  186. for thread in fourchan.get_threads("jp"):
  187. if thread.title == "hololive":
  188. jp_thread_no = thread.number
  189. break
  190.  
  191.  
  192. def check_jp_thread():
  193. global jp_thread_no, jp_thread_imgcount, jp_thread_replycount, BEG_DELAY, LAST_REPLYCOUNT, IMG_GENKAI_TOPPA
  194. find_jp_thread()
  195. jp_thread = Thread("jp", jp_thread_no)
  196. driver.get(jp_thread.url)
  197. element = driver.find_element(By.CLASS_NAME, "ts-replies")
  198. jp_thread_replycounttext = element.get_property("innerText")
  199. try:
  200. jp_thread_replycount = int(jp_thread_replycounttext)
  201. except ValueError:
  202. time.sleep(GOFUN)
  203. print("Current /jp/ thread reply count is: " + str(jp_thread_replycount))
  204. element = driver.find_element(By.CLASS_NAME, "ts-images")
  205. imagecounttext = element.get_property("innerText")
  206. jp_thread_imgcount = int(imagecounttext)
  207. if jp_thread_imgcount >= 300:
  208. IMG_GENKAI_TOPPA = True
  209. else:
  210. IMG_GENKAI_TOPPA = False
  211. print("Current /jp/ thread file count is: " + str(jp_thread_imgcount))
  212. if LAST_REPLYCOUNT == 0: #first loop
  213. LAST_REPLYCOUNT = jp_thread_replycount
  214. else:
  215. new_replycount = jp_thread_replycount - LAST_REPLYCOUNT
  216. if new_replycount < 0: #thread changed
  217. BEG_DELAY = GOFUN
  218. LAST_REPLYCOUNT = jp_thread_replycount
  219. else:
  220. BEG_DELAY = int(BEG_DELAY_FACTOR / new_replycount)
  221. LAST_REPLYCOUNT = jp_thread_replycount
  222. if IMG_GENKAI_TOPPA:
  223. BEG_DELAY = int(BEG_DELAY / 2)
  224.  
  225.  
  226. def make_pasta():
  227. global nextpastatext
  228.  
  229. nextpastatext = ""
  230. pasta_loop_count = 0
  231. jp_thread = Thread("jp", jp_thread_no)
  232. nextmemberthread = Thread("vt", vt_thread_numbers[nextmember])
  233. while not nextpastatext:
  234. nextmemberfound = False
  235. nextpasta = random.choice(fourchan.get_posts(nextmemberthread))
  236. nextpastatext = nextpasta.text
  237. if (("youtu.be" in nextpastatext) or ("x.com" in nextpastatext) or ("twitter.com" in nextpastatext) or
  238. ("https://" in nextpastatext) or (">>" in nextpastatext)):
  239. nextpastatext = ""
  240. match nextmember:
  241. case 0:
  242. if ("baelz" in nextpastatext.lower()) or ("bae" in nextpastatext.lower()):
  243. nextmemberfound = True
  244. case 1:
  245. if ("bijou" in nextpastatext.lower()) or ("biboo" in nextpastatext.lower()):
  246. nextmemberfound = True
  247. case 2:
  248. if ("fau" in nextpastatext.lower()) or ("ceres" in nextpastatext.lower()):
  249. nextmemberfound = True
  250. case 3:
  251. if ("fuwa" in nextpastatext.lower()) or ("moco" in nextpastatext.lower()):
  252. nextmemberfound = True
  253. case 4:
  254. if ("guwa" in nextpastatext.lower()) or ("gura" in nextpastatext.lower()):
  255. nextmemberfound = True
  256. case 5:
  257. if "ina" in nextpastatext.lower():
  258. nextmemberfound = True
  259. case 6:
  260. if "irys" in nextpastatext.lower():
  261. nextmemberfound = True
  262. case 7:
  263. if ("kiara" in nextpastatext.lower()) or ("kiwawa" in nextpastatext.lower()):
  264. nextmemberfound = True
  265. case 8:
  266. if "kronii" in nextpastatext.lower():
  267. nextmemberfound = True
  268. case 9:
  269. if 'mori' in nextpastatext.lower():
  270. nextmemberfound = True
  271. case 10:
  272. if ('mumei' in nextpastatext.lower()) or ("moom" in nextpastatext.lower()):
  273. nextmemberfound = True
  274. case 11:
  275. if "rissa" in nextpastatext.lower():
  276. nextmemberfound = True
  277. case 12:
  278. if 'shiori' in nextpastatext.lower():
  279. nextmemberfound = True
  280. if not nextmemberfound:
  281. nextpastatext = ""
  282. for post in fourchan.get_posts(jp_thread):
  283. if post.text == nextpastatext:
  284. nextpastatext = ""
  285. pasta_loop_count += 1
  286. if pasta_loop_count > 100:
  287. nextpastatext = "Burnt the water, now the pasta is ruined."
  288. if nextpastatext == "Burnt the water, now the pasta is ruined.":
  289. nextpastatext = ""
  290. else:
  291. print("Gonna post this, lol: " + nextpastatext)
  292.  
  293.  
  294. def strain_the_pasta():
  295. global nextpastatext, nextmember
  296. first_pasta_attempt = True
  297. nextpastatext = ""
  298. while not nextpastatext:
  299. if not first_pasta_attempt:
  300. find_vt_threads()
  301.  
  302. nextmemberthreadnumber = 0
  303. while nextmemberthreadnumber == 0:
  304. nextmember = random.randint(0, CURRENT_MAX)
  305. nextmemberthreadnumber = vt_thread_numbers[nextmember]
  306. nextmemberthread = Thread("vt", vt_thread_numbers[nextmember])
  307. if nextmemberthread.is_closed or nextmemberthread.is_archived:
  308. nextmemberthreadnumber = 0
  309. vt_thread_numbers[nextmember] = nextmemberthreadnumber
  310.  
  311. if img_counts[nextmember] == img_totals[nextmember]:
  312. random.shuffle(img_lists[nextmember])
  313. img_counts[nextmember] = 0
  314.  
  315. make_pasta()
  316. first_pasta_attempt = False
  317.  
  318.  
  319. init_img_folders()
  320. find_vt_threads()
  321. loop_count = 0
  322. while True:
  323.  
  324. loop_count += 1
  325. if loop_count > 33:
  326. find_vt_threads()
  327. loop_count = 0
  328.  
  329. check_jp_thread()
  330.  
  331. print("Current beg delay: " + str(BEG_DELAY))
  332. time.sleep(random.randint(BEG_DELAY, (BEG_DELAY + IPPUN)))
  333.  
  334. element = driver.find_element(By.PARTIAL_LINK_TEXT, "Post a")
  335. element.click()
  336. time.sleep(IPPUN)
  337.  
  338. if IMG_GENKAI_TOPPA:
  339. strain_the_pasta()
  340. element = driver.find_element(By.NAME, "com")
  341. element.send_keys(nextpastatext)
  342. else:
  343. nextmember = random.randint(0, CURRENT_MAX)
  344. nextbegimage = os.path.join(img_directories[nextmember],
  345. img_lists[nextmember][img_counts[nextmember]])
  346. element = driver.find_element(By.ID, "postFile")
  347. element.send_keys(nextbegimage)
  348. img_counts[nextmember] += 1
  349.  
  350. element = driver.find_element(By.ID, "t-load")
  351. element.click()
  352. time.sleep(IPPUN)
  353.  
  354. element = driver.find_element(By.ID, "t-resp")
  355. element.send_keys(Keys.RETURN)
  356. print("Posted it, lol. 30 sec wait...")
  357. time.sleep(ITTAN)
  358.  
  359.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement