-
Notifications
You must be signed in to change notification settings - Fork 0
/
dc-u-i.py
187 lines (174 loc) · 5.23 KB
/
dc-u-i.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/python3
#Licensed under the 2-Clause BSD License
# 0.0000233333333333333 b
#Slack Crow 2017
import csv
import sys
import os
import requests
import json
import time
currentBoard = ""
currentPage = 0
currentThread = 0
currentPost = 0
#clears the current console
def clear():
os.system('cls' if os.name=='nt' else 'clear')
def printTop():
global currentBoard
global currentPage
print("----------------------------------")
print("-----Welcome to Danger/u/ BBS-----")
print("----------------------------------")
print("Interests Misc.")
print("")
print("Anime & Manga(a) Random(u)")
print("Cyberpunk(cyb) Burg(burg)")
print("Doujin(d) News(new)")
print("music(mu)")
print("Technology(tech)")
print("Video Games(v)")
print("")
print("Goto?")
currentBoard = input()
currentPage = 0
clear()
def getBoard():
jsonReceived = requests.get("https://boards.dangeru.us/api.php?type=index&board=" + currentBoard + "&ln=" + "250")
jsonReceived = jsonReceived.text.replace('\n', ' ').replace('\r', '')
return jsonReceived
def getBoardName(boardID):
if boardID == "a":
return "Anime & Manga"
elif boardID == "cyb":
return "Cyberpunk"
elif boardID == "d":
return "Doujin"
elif boardID == "tech":
return "Technology"
elif boardID == "v":
return "Video Games"
elif boardID == "u":
return "Random"
elif boardID == "burg":
return "Burg"
elif boardID == "new":
return "News"
else:
return "null"
def getThread():
jsonReceived = requests.get("https://boards.dangeru.us/api.php?type=thread&board=" + currentBoard + "&ln=" + "100" + "&thread=" + str(currentThread))
jsonReceived = jsonReceived.text.replace('\n', ' ').replace('\r', '')
return jsonReceived
def printCurrent():
print("You are now at... "+ getBoardName(currentBoard))
print("Page "+str(currentPage+1))
def printThread():
global currentPost
processedFetch = json.loads(getThread())
print("----------------------------------")
print("Title:" + processedFetch["meta"][0]["title"])
print("----------------------------------")
i = 9*currentPost
while i < len(processedFetch["replies"]) and i < 9*(currentPost+1):
print("- "+processedFetch["replies"][i]["post"])
i = i + 1
print("----------------------------------")
print("next(n)/before(b)/return(r)/write(w)")
toDo = input()
if toDo[0] == "r":
clear()
printBoard()
elif toDo[0] == "n":
currentPost = currentPost + 1
clear()
printThread()
elif toDo[0] == "b":
if currentPost == 0:
print("There is no previous page")
else:
currentPost = currentPost - 1
clear()
printThread()
elif toDo[0] == "w":
postComment()
else:
print("error")
def postThread():
clear()
print("Title")
print("----------------------------------")
title = input()
clear()
print("Body")
print("\"#submit\" to submit")
print("----------------------------------")
userInput = input()
body = userInput
while (not(userInput == "#submit")):
userInput = input()
if not userInput == "#submit":
body = body + "/n" + userInput
body = body.replace(" ","%20")
title = title.replace(" ","%20")
requests.get("https://boards.dangeru.us/api.php?type=post&board=" + currentBoard + "&title=" + title + "&body=" + body)
clear()
printBoard()
def postComment():
print("\"#submit\" to submit")
print("----------------------------------")
userInput = input()
body = userInput
while (not(userInput == "#submit")):
userInput = input()
if not userInput == "#submit":
body = body + "/n" + userInput
body = body.replace(" ","%20")
requests.get("https://boards.dangeru.us/api.php?type=comment&board=" + currentBoard + "&thread=" + str(currentThread) + "&body=" + body)
clear()
printThread()
def printBoard():
global currentThread
global currentPage
threadList = json.loads(getBoard())
printCurrent()
i = 9*currentPage
print("----------------------------------")
while i < len(threadList[u'threads']) and i < 9*(currentPage+1):
print(str(i)+". "+ threadList[u'threads'][i][u'title'])
i = i + 1
print("----------------------------------")
print("goto(g) <>/next(n)/before(b)/top(t)/write(w)")
toDo = input()
if toDo[0] == "g":
clear()
currentThread = threadList[u'threads'][int(toDo[2:])][u'id']
printThread()
elif toDo[0] == "t":
main()
elif toDo[0] == "n":
currentPage = currentPage + 1
clear()
printBoard()
elif toDo[0] == "n":
currentPage = currentPage + 1
clear()
printBoard()
elif toDo[0] == "b":
if currentPage == 0:
print("There is no previous page")
else:
currentPage = currentPage - 1
clear()
printBoard()
elif toDo[0] == "w":
postThread()
else:
print("error, returing to top")
main()
def main():
clear()
printTop()
printBoard()
main()