import requests import json import webbrowser print("Sucklessg low effort Python client") API_URL = "https://sucklessg.org" current_page = 0 running = True def render_post(id, content, created, replies): print("ID: " + str(id)) print(content) print("Reply count: " + str(replies)) print("Created: " + created) print("\n") def render_page(page_json): for i in page_json: render_post(i["id"], i["content"], i["created"], i["replies"]) print("Page: " + str(current_page)) def render_thread(thread_json): for i in thread_json: render_post(i["id"], i["content"], i["created"], None) print("End of thread") # block to allow reading input() def get_request(_url): request = requests.get(url = _url) if request.status_code != 200: return None else: return request.json() def post_request(url, data): request = requests.post(url, data = data) if request.status_code != 200: return None else: return request.json() def load_page(page_number): return get_request(API_URL+"/page/"+str(current_page)) def load_thread(thread_id): return get_request(API_URL+"/post/"+str(thread_id)) def get_captcha(): return get_request(API_URL+"/captcha") def write_captcha_to_html(captcha): file = open("captcha.html", "w") file.write(captcha["captcha_svg"]) def open_captcha(captcha): write_captcha_to_html(captcha) webbrowser.open("captcha.html", new=2) print("Captcha opened in web browser") return input("Solution?: ") def create_thread(content, captcha_id, captcha_solution): thread = post_request(API_URL+"/post", { "content": content, "captcha_id": captcha_id, "captcha_solution": captcha_solution }) render_thread(load_thread(thread["id"])) def create_reply(content, captcha_id, captcha_solution, on_thread): thread = post_request(API_URL+"/post", { "content": content, "captcha_id": captcha_id, "captcha_solution": captcha_solution, "on_thread": on_thread }) render_thread(load_thread(on_thread)) while running: # fetch and render page by current_page number page_json = load_page(current_page) if page_json is None: print("Something dun fucked up") else: render_page(page_json) # get input on action print("1) Go to the next page\n2) Go back a page\n3) Enter a thread\n4) Create a thread\n5) Exit") action = input("Action?: ") # increment current page if action == "1": if current_page >= 9: print("No more pages for you faggot") else: current_page+=1 # deincrement current page elif action == "2": if current_page <= 0: print("gay dumb negative fag") else: current_page-=1 # render a thread, ask for the thread id elif action == "3": thread_id = input("Thread ID?: ") thread_json = load_thread(thread_id) if thread_json is None: print("baaaaaakkaaaa") else: render_thread(thread_json) # block to allow user to read thread print("1) Post reply\n2) Exit thread") thread_action = input("Action?: ") if thread_action == "1": reply_content = input("Reply content: ") captcha = get_captcha() if captcha is None: print("ass") else: captcha_solution = open_captcha(captcha) create_reply(reply_content, captcha["captcha_id"], captcha_solution, thread_id) print("\n") elif thread_action == "2": exit # create a thread elif action == "4": thread_content = input("Thread content: ") # get captcha captcha = get_captcha() if captcha is None: print("fuck!") else: captcha_solution = open_captcha(captcha) create_thread(thread_content, captcha["captcha_id"], captcha_solution) print("\n") elif action == "5": running = False