-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
be - preprocess - add ETA, save the latest guild and channel names an…
…d icons, less verbose logs, remove old channel cache, remove unused sha256 json hash
- Loading branch information
Showing
10 changed files
with
176 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import time | ||
|
||
from Formatters import Formatters | ||
|
||
|
||
class Eta: | ||
def __init__(self, max_value, count): | ||
self.bulgarian_constant = 50000 | ||
self.max_value = max_value + count * self.bulgarian_constant | ||
self.current_value = 0 | ||
self.time_started = time.time() | ||
self.last_increment_time = self.time_started | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, exc_traceback): | ||
if exc_type is not None: | ||
raise exc_type(exc_value).with_traceback(exc_traceback) | ||
return True | ||
|
||
def calculate_eta(self): | ||
if self.current_value == 0: | ||
return "N/A" | ||
else: | ||
eta = (time.time() - self.time_started) / self.current_value * (self.max_value - self.current_value) - (time.time() - self.last_increment_time) | ||
return Formatters.human_time(eta) | ||
|
||
def increment(self, add_value): | ||
self.current_value += add_value + self.bulgarian_constant | ||
self.last_increment_time = time.time() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Formatters: | ||
@staticmethod | ||
def human_file_size(file_size_bytes: int) -> str: | ||
""" | ||
returns file size in human readable format | ||
""" | ||
# round to 2 decimal places | ||
if file_size_bytes < 1024: | ||
return f'{file_size_bytes} B' | ||
elif file_size_bytes < 1024 * 1024: | ||
return f'{round(file_size_bytes / 1024, 2)} KB' | ||
elif file_size_bytes < 1024 * 1024 * 1024: | ||
return f'{round(file_size_bytes / 1024 / 1024, 2)} MB' | ||
else: | ||
return f'{round(file_size_bytes / 1024 / 1024 / 1024, 2)} GB' | ||
|
||
@staticmethod | ||
def human_time(seconds_total: int) -> str: | ||
""" | ||
returns time in format HH:MM:SS | ||
""" | ||
hours, remainder = divmod(seconds_total, 3600) | ||
minutes, seconds = divmod(remainder, 60) | ||
return f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}" | ||
|
||
@staticmethod | ||
def pad_id(id: int) -> str: | ||
if id == None: | ||
return None | ||
return str(id).zfill(24) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.