Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import requests
  2. import json
  3. print("Sucklessg low effort Python client")
  4.  
  5. API_URL = "https://sucklessg.org"
  6. current_page = 0
  7.  
  8. def render_post(id, content, created, replies):
  9. print("ID: " + str(id))
  10. print(content)
  11. print("Reply count: " + str(replies))
  12. print("Created: " + created)
  13. print("\n")
  14.  
  15. def render_page(page_json):
  16. for i in page_json:
  17. render_post(i["id"], i["content"], i["created"], i["replies"])
  18.  
  19. print("Page: " + str(current_page))
  20.  
  21. def render_thread(thread_json):
  22. for i in thread_json:
  23. render_post(i["id"], i["content"], i["created"], None)
  24.  
  25. print("End of thread")
  26.  
  27. def load_page(page_number):
  28. page = requests.get(url = API_URL+"/page/"+str(current_page))
  29. if page.status_code != 200:
  30. return None
  31. else:
  32. return page.json()
  33.  
  34. def load_thread(thread_id):
  35. thread = requests.get(url = API_URL+"/post/"+thread_id)
  36. if thread.status_code != 200:
  37. return None
  38. else:
  39. return thread.json()
  40.  
  41. while True:
  42. # fetch and render page by current_page number
  43. page_json = load_page(current_page)
  44. if page_json is None:
  45. print("Something dun fucked up")
  46. else:
  47. render_page(page_json)
  48. # get input on action
  49. print("1) Go to the next page\n2) Go back a page\n3) Enter a thread\n")
  50. action = input("Action?: ")
  51. # increment current page
  52. if action == "1":
  53. if current_page >= 9:
  54. print("No more pages for you faggot")
  55. else:
  56. current_page+=1
  57. # deincrement current page
  58. elif action == "2":
  59. if current_page <= 0:
  60. print("gay dumb negative fag")
  61. else:
  62. current_page-=1
  63. # render a thread, ask for the thread id
  64. elif action == "3":
  65. thread_id = input("Thread ID?: ")
  66. thread_json = load_thread(thread_id)
  67. if thread_json is None:
  68. print("baaaaaakkaaaa")
  69. else:
  70. render_thread(thread_json)
  71. # block to allow user to read thread
  72. input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement