Skip to content

Commit

Permalink
Update Palworld.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Mar 13, 2024
1 parent 6dea6e1 commit a8d27aa
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions protocols/Palworld.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from concurrent.futures import ThreadPoolExecutor, wait, FIRST_COMPLETED
from datetime import datetime, timezone
from pymongo import UpdateOne
from tqdm import tqdm
Expand Down Expand Up @@ -60,29 +59,15 @@ def _upsert_bulk_write(self, server_list: list):

def _fetch_until_empty(self):
servers = []
stop = False
pbar = tqdm(total=0, desc=f'[{self.key}] Fetch Page')
pbar = tqdm(total=1, desc=f'[{self.key}] Fetch Page')

with ThreadPoolExecutor() as executor:
futures = {executor.submit(self._fetch_page, pbar.total + 1)}
while pbar.n < pbar.total:
if server_list := self._fetch_page(pbar.total):
servers.extend(server_list)
pbar.total += 1

while futures:
done, futures = wait(futures, return_when=FIRST_COMPLETED)

for future in done:
server_list = future.result()

if server_list:
servers.extend(server_list)
pbar.update(1)
else:
stop = True

if not stop:
pbar.total += 1
pbar.refresh()
futures.add(executor.submit(
self._fetch_page, pbar.total + 1))
pbar.update(1)
pbar.refresh()

return servers

Expand Down

0 comments on commit a8d27aa

Please sign in to comment.