Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. import requests
  2. import json
  3. import webbrowser
  4. print("Sucklessg low effort Python client")
  5.  
  6. API_URL = "https://sucklessg.org"
  7. current_page = 0
  8. running = True
  9.  
  10. def render_post(id, content, created, replies):
  11. print("ID: " + str(id))
  12. print(content)
  13. print("Reply count: " + str(replies))
  14. print("Created: " + created)
  15. print("\n")
  16.  
  17. def render_page(page_json):
  18. for i in page_json:
  19. render_post(i["id"], i["content"], i["created"], i["replies"])
  20.  
  21. print("Page: " + str(current_page))
  22.  
  23. def render_thread(thread_json):
  24. for i in thread_json:
  25. render_post(i["id"], i["content"], i["created"], None)
  26.  
  27. print("End of thread")
  28. # block to allow reading
  29. input()
  30.  
  31. def get_request(_url):
  32. request = requests.get(url = _url)
  33. if request.status_code != 200:
  34. return None
  35. else:
  36. return request.json()
  37.  
  38. def post_request(url, data):
  39. request = requests.post(url, data = data)
  40. if request.status_code != 200:
  41. return None
  42. else:
  43. return request.json()
  44.  
  45. def load_page(page_number):
  46. return get_request(API_URL+"/page/"+str(current_page))
  47.  
  48.  
  49. def load_thread(thread_id):
  50. return get_request(API_URL+"/post/"+str(thread_id))
  51.  
  52. def get_captcha():
  53. return get_request(API_URL+"/captcha")
  54.  
  55. def write_captcha_to_html(captcha):
  56. file = open("captcha.html", "w")
  57. file.write(captcha["captcha_svg"])
  58.  
  59. def open_captcha(captcha):
  60. write_captcha_to_html(captcha)
  61. webbrowser.open("captcha.html", new=2)
  62. print("Captcha opened in web browser")
  63. return input("Solution?: ")
  64.  
  65. def create_thread(content, captcha_id, captcha_solution):
  66. thread = post_request(API_URL+"/post", {
  67. "content": content,
  68. "captcha_id": captcha_id,
  69. "captcha_solution": captcha_solution
  70. })
  71. render_thread(load_thread(thread["id"]))
  72.  
  73. def create_reply(content, captcha_id, captcha_solution, on_thread):
  74. thread = post_request(API_URL+"/post", {
  75. "content": content,
  76. "captcha_id": captcha_id,
  77. "captcha_solution": captcha_solution,
  78. "on_thread": on_thread
  79. })
  80. render_thread(load_thread(on_thread))
  81.  
  82. while running:
  83. # fetch and render page by current_page number
  84. page_json = load_page(current_page)
  85. if page_json is None:
  86. print("Something dun fucked up")
  87. else:
  88. render_page(page_json)
  89. # get input on action
  90. print("1) Go to the next page\n2) Go back a page\n3) Enter a thread\n4) Create a thread\n5) Exit")
  91. action = input("Action?: ")
  92. # increment current page
  93. if action == "1":
  94. if current_page >= 9:
  95. print("No more pages for you faggot")
  96. else:
  97. current_page+=1
  98. # deincrement current page
  99. elif action == "2":
  100. if current_page <= 0:
  101. print("gay dumb negative fag")
  102. else:
  103. current_page-=1
  104. # render a thread, ask for the thread id
  105. elif action == "3":
  106. thread_id = input("Thread ID?: ")
  107. thread_json = load_thread(thread_id)
  108. if thread_json is None:
  109. print("baaaaaakkaaaa")
  110. else:
  111. render_thread(thread_json)
  112. # block to allow user to read thread
  113. print("1) Post reply\n2) Exit thread")
  114. thread_action = input("Action?: ")
  115. if thread_action == "1":
  116. reply_content = input("Reply content: ")
  117. captcha = get_captcha()
  118. if captcha is None:
  119. print("ass")
  120. else:
  121. captcha_solution = open_captcha(captcha)
  122. create_reply(reply_content, captcha["captcha_id"], captcha_solution, thread_id)
  123. print("\n")
  124. elif thread_action == "2":
  125. exit
  126.  
  127. # create a thread
  128. elif action == "4":
  129. thread_content = input("Thread content: ")
  130. # get captcha
  131. captcha = get_captcha()
  132. if captcha is None:
  133. print("fuck!")
  134. else:
  135. captcha_solution = open_captcha(captcha)
  136. create_thread(thread_content, captcha["captcha_id"], captcha_solution)
  137. print("\n")
  138. elif action == "5":
  139. running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement