-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewbot.py
More file actions
155 lines (136 loc) · 5.06 KB
/
Copy pathviewbot.py
File metadata and controls
155 lines (136 loc) · 5.06 KB
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
import sys, os, time, datetime, asyncio, aiohttp
f = open('/dev/null', 'w')
sys.stderr = f
def moveCursor(x, y):
sys.stdout.write("\033[" + str(y) + ";" + str(x) + "H")
sys.stdout.flush()
# | dark | bright |
# --------+------+--------+
# black | 0 | 8 |
# red | 1 | 9 |
# green | 2 | 10 |
# yellow | 3 | 11 |
# blue | 4 | 12 |
# magenta | 5 | 13 |
# cyan | 6 | 14 |
# white | 7 | 15 |
def writeText(x, y, text, fcolor=None, bcolor=None):
if fcolor == None:
pass
elif type(fcolor) != int:
raise TypeError("writeText()'s 'fcolor' attribute must be an Int or None.")
elif (fcolor > -1) and (fcolor < 8):
sys.stdout.write("\033[" + str(fcolor+30) + "m")
elif (fcolor > 7) and (fcolor < 16):
sys.stdout.write("\033[" + str(fcolor+22) + ";1m")
else:
raise ValueError("writeText()'s 'fcolor' attribute must be between 0 and 15.")
if bcolor == None:
pass
elif type(bcolor) != int:
raise TypeError("writeText()'s 'bcolor' attribute must be an Int or None.")
elif (bcolor > -1) and (bcolor < 8):
sys.stdout.write("\033[" + str(bcolor+40) + "m")
else:
raise ValueError("writeText()'s 'bcolor' attribute must be between 0 and 7.")
moveCursor(x, y)
sys.stdout.write(text)
sys.stdout.write("\u001b[0m")
sys.stdout.flush()
async def writeTextA(x, y, text, fcolor=None, bcolor=None):
if fcolor == None:
pass
elif type(fcolor) != int:
raise TypeError("writeText()'s 'fcolor' attribute must be an Int or None.")
elif (fcolor > -1) and (fcolor < 8):
sys.stdout.write("\033[" + str(fcolor+30) + "m")
elif (fcolor > 7) and (fcolor < 16):
sys.stdout.write("\033[" + str(fcolor+22) + ";1m")
else:
raise ValueError("writeText()'s 'fcolor' attribute must be between 0 and 15.")
if bcolor == None:
pass
elif type(bcolor) != int:
raise TypeError("writeText()'s 'bcolor' attribute must be an Int or None.")
elif (bcolor > -1) and (bcolor < 8):
sys.stdout.write("\033[" + str(bcolor+40) + "m")
else:
raise ValueError("writeText()'s 'bcolor' attribute must be between 0 and 7.")
moveCursor(x, y)
sys.stdout.write(text)
sys.stdout.write("\u001b[0m")
sys.stdout.flush()
def bell():
sys.stdout.write("\007")
sys.stdout.flush()
def clearLine(line):
moveCursor(1, line)
sys.stdout.write(" "*120)
sys.stdout.flush()
async def clock():
while True:
await writeTextA(113, 1, datetime.datetime.now().strftime("%I:%M %p"), 12, 7)
await asyncio.sleep(1)
version = "0.6"
view_count = 0
timeouts = 0
os.system("clear")
writeText(1, 1, "rcViewbot Ver. " + version, 0, 3)
writeText(1, 2, "Total Views: ", 0, 7)
writeText(14, 2, "0", 15, 4)
async def inc_count(_type):
global view_count
global timeouts
if _type: view_count += 1
else: timeouts += 1
await writeTextA(14, 2, str(view_count).rjust(7), 15, 4)
await writeTextA(21, 2, "+", 0, 7)
await writeTextA(22, 2, str(timeouts).rjust(5), 15, 1)
async def inner_loop(session, id, b):
a = await session.request("GET", "https://tbgforums.com/forums/viewtopic.php?id="+str(id))
#print(a.status, b)
await writeTextA(4, 4+b, str(a.status), 0, 2)
async def middle_loop(session, id, b, timeout):
global reps
global touts
await writeTextA(1, 4+b, str(b).rjust(2))
#print(b, "start")
while True:
try:
await asyncio.wait_for(inner_loop(session, id, b), timeout)
reps[b] += 1
await writeTextA(8, 4+b, str(reps[b]).rjust(7), 6)
await inc_count(True)
await asyncio.sleep(0.25)
except KeyboardInterrupt:
sys.exit()
except (asyncio.TimeoutError, asyncio.futures.TimeoutError, TimeoutError):
touts[b] += 1
await writeTextA(16, 4+b, str(touts[b]).rjust(4), 1)
await inc_count(False)
await writeTextA(4, 4+b, "out", 0, 1)
except (ConnectionResetError, aiohttp.client_exceptions.ClientConnectionError):
await writeTextA(4, 4+b, "cce", 0, 5)
except Exception:
raise
#print("timeout", b)
async def outer_loop(id, count):
#connector = aiohttp.TCPConnector(force_close=True)
#async with aiohttp.ClientSession(connector=connector) as session:
async with aiohttp.ClientSession() as session:
tasks = []
for i in range(count):
tasks.append(middle_loop(session, id, i, 1))
tasks.append(clock())
await asyncio.gather(*tasks)
#await asyncio.gather(asyncio.create_task(inner_loop(id, 1)), asyncio.create_task(inner_loop(id, 2)), asyncio.create_task(inner_loop(id, 3)), asyncio.create_task(inner_loop(id, 4)))
writeText(1, 3, "Thread ID ")
tID = int(input("> "))
writeText(1, 4, "Concurrent View Count (max 16) ")
vCount = min(int(input("> ")), 16)
reps = [0]*vCount
touts = [0]*vCount
clearLine(3)
clearLine(4)
writeText(115, 2, str(tID).rjust(6), 15, 7)
asyncio.run(outer_loop(tID, vCount))