Skip to content

Commit 013d4ba

Browse files
committed
getting chunks in the loop
1 parent 48f45be commit 013d4ba

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

main.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,14 @@ def call_nzbget_direct(url_command):
219219
http_url = "http://%s:%s/jsonrpc/%s" % (HOST, PORT, url_command)
220220
request = urllib.request.Request(http_url)
221221
base_64_string = (
222-
base64.b64encode(("%s:%s" % (USERNAME, PASSWORD)).encode("utf-8")).decode("utf-8").strip()
222+
base64.b64encode(("%s:%s" % (USERNAME, PASSWORD)).encode("utf-8"))
223+
.decode("utf-8")
224+
.strip()
223225
)
224226
request.add_header("Authorization", "Basic %s" % base_64_string)
225227
response = urllib.request.urlopen(request) # get some data from NZBGet
226228
# data is a JSON raw-string, contains ALL properties each NZB in queue
227-
data = response.read().decode('utf-8')
229+
data = response.read().decode("utf-8")
228230
return data
229231

230232

@@ -1041,7 +1043,9 @@ def get_server_settings(nzb_age):
10411043
return servers
10421044

10431045

1044-
def create_sockets(server, articles_to_check) -> Tuple[list[ssl.SSLSocket], list[int], int]:
1046+
def create_sockets(
1047+
server, articles_to_check
1048+
) -> Tuple[list[ssl.SSLSocket], list[int], int]:
10451049
"""
10461050
create the sockets for the server that will be used to send in
10471051
check_send_server_reply() and receive in check_failure_status()
@@ -1213,6 +1217,7 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
12131217
socket_loop_count = [-1] * num_conn
12141218
failed_wait_count = 0
12151219
loop_fail = False
1220+
chunk = 4096
12161221
start_time = time.time()
12171222
print("Using server: " + host)
12181223
sys.stdout.flush()
@@ -1253,13 +1258,11 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
12531258
if send_articles > articles_to_check - 1:
12541259
break
12551260
try:
1256-
1257-
data = sockets[i].recv(4096)
1258-
reply = data.read().decode("utf-8")
1259-
print('DETAIL ___REPLY___', str(reply))
1261+
data = sockets[i].recv(chunk)
1262+
reply = ""
12601263
while data:
1261-
data = sockets[i].recv(4096)
1262-
reply += data.read().decode("utf-8")
1264+
reply += data.decode("utf-8")
1265+
data = sockets[i].recv(chunk)
12631266
except: # each error would trigger the same effect
12641267
# avoid continuous looping on fast machines by adding delays
12651268
# EAGAIN, EWOULDBLOCK, ssl.SSLWantReadError
@@ -1319,7 +1322,9 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
13191322
+ " marking requested article as failed."
13201323
)
13211324
sys.stdout.flush()
1322-
reply = "999 Article marked as failed by script.".encode(encoding="utf-8")
1325+
reply = "999 Article marked as failed by script.".encode(
1326+
encoding="utf-8"
1327+
)
13231328
failed_wait_count += 1
13241329
if failed_wait_count >= 20:
13251330
print(
@@ -1412,12 +1417,11 @@ def check_failure_status(rar_msg_ids, failed_limit, nzb_age):
14121417
for i in socket_list[m:]: # loop through ok sockets
14131418
reply = None
14141419
try:
1415-
data = sockets[i].recv(4096)
1416-
reply = data.read().decode("utf-8")
1417-
print('DETAIL ___REPLY___', str(reply))
1420+
data = sockets[i].recv(chunk)
1421+
reply = ""
14181422
while data:
1419-
data = sockets[i].recv(4096)
1420-
reply += data.read().decode("utf-8")
1423+
reply += data.decode("utf-8")
1424+
data = sockets[i].recv(chunk)
14211425
except: # managing all socket errors
14221426
err = sys.exc_info()
14231427
if socket_loop_count[i] < 5:

0 commit comments

Comments
 (0)