start.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. from VerificationCode.mcbbs.SignIn import main_sign_in
  2. from VerificationCode.mcbbs.reply import reply
  3. from timing.time import set_time
  4. from VerificationCode.mcbbs.task import get_new_tasks, complete_tasks
  5. from selenium import webdriver
  6. from loginTools.login import login
  7. from loginTools.include_all_cookies import include_all_cookies
  8. from selenium.common.exceptions import NoSuchWindowException, NoSuchElementException, WebDriverException
  9. import time
  10. import threading
  11. import random
  12. def main():
  13. threads = [threading.Thread(target=main_reply), threading.Thread(target=main_tasks_and_sign)]
  14. for t in threads:
  15. t.start()
  16. print(t)
  17. def main_reply():
  18. while True:
  19. set_time(one_reply, (1,), " 08:00:00")
  20. set_time(one_reply, (0,), " 12:00:00")
  21. set_time(one_reply, (0,), " 16:00:00")
  22. set_time(one_reply, (0,), " 20:00:00")
  23. set_time(one_reply, (0,), " 00:00:00")
  24. time.sleep(86400)
  25. def one_reply(flag):
  26. cookies = include_all_cookies()
  27. for cookie_path in cookies:
  28. while True:
  29. try:
  30. driver = webdriver.Chrome()
  31. if not login(driver, cookie_path):
  32. driver.quit()
  33. break
  34. urls = ['https://www.mcbbs.net/forum-texture-%d.html',
  35. 'https://www.mcbbs.net/forum-accessories-%d.html',
  36. 'https://www.mcbbs.net/forum-map-%d.html',
  37. 'https://www.mcbbs.net/forum-mapcarry-%d.html',
  38. 'https://www.mcbbs.net/forum-mapchat-%d.html',
  39. 'https://www.mcbbs.net/forum-moddiscussion-%d.html',
  40. 'https://www.mcbbs.net/forum-modtutorial-%d.html',
  41. 'https://www.mcbbs.net/forum-mod-%d.html',
  42. 'https://www.mcbbs.net/forum-modpack-%d.html',
  43. 'https://www.mcbbs.net/forum-multiplayer-%d.html',
  44. 'https://www.mcbbs.net/forum-servermod-%d.html',
  45. 'https://www.mcbbs.net/forum-serverpack-%d.html',
  46. 'https://www.mcbbs.net/forum-gameplay-%d.html']
  47. if flag == 1:
  48. time.sleep(10)
  49. r = random.randint(1, 30)
  50. r = str(r)
  51. reply(driver,
  52. 'https://www.mcbbs.net/forum-chat-' + r + '.html')
  53. i = 2
  54. while i >= 1:
  55. time.sleep(10)
  56. url_num = random.randint(0, 12)
  57. temp = urls[url_num]
  58. r = random.randint(1, 5)
  59. url = temp % r
  60. reply(driver, url)
  61. i = i - 1
  62. driver.quit()
  63. except NoSuchWindowException:
  64. print('except NoSuchWindowException')
  65. continue
  66. except WebDriverException:
  67. print('except WebDriverException')
  68. continue
  69. else:
  70. break
  71. def main_tasks_and_sign():
  72. while True:
  73. tasks()
  74. time.sleep(86400)
  75. def tasks():
  76. driver_another = webdriver.Firefox()
  77. set_time(get_tasks_and_sign_in, (driver_another,), " 07:30:00")
  78. set_time(final_complete_tasks, (driver_another,), " 19:30:00")
  79. def get_tasks_and_sign_in(driver):
  80. while True:
  81. try:
  82. cookies = include_all_cookies()
  83. for cookie_path in cookies:
  84. if not login(driver, cookie_path):
  85. continue
  86. while True:
  87. try:
  88. main_sign_in(driver)
  89. get_new_tasks(driver)
  90. except WebDriverException:
  91. continue
  92. else:
  93. break
  94. except NoSuchElementException:
  95. continue
  96. else:
  97. break
  98. def final_complete_tasks(driver):
  99. while True:
  100. try:
  101. cookies = include_all_cookies()
  102. for cookie_path in cookies:
  103. if not login(driver, cookie_path):
  104. continue
  105. complete_tasks(driver)
  106. except NoSuchElementException:
  107. continue
  108. else:
  109. break
  110. if __name__ == '__main__':
  111. main()