diff --git a/requirements.txt b/requirements.txt index be6a773..1511f80 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ bs4~=0.0.1 -beautifulsoup4~=4.12.2 -fishhook~=0.2.9 -requests~=2.31.0 +beautifulsoup4~=4.12 +requests~=2.32 tqdm~=4.66 \ No newline at end of file diff --git a/src/tools/tools.py b/src/tools/tools.py index d9169fb..63f5cdb 100644 --- a/src/tools/tools.py +++ b/src/tools/tools.py @@ -2,8 +2,6 @@ import datetime import inspect import os.path import sys -from fishhook import hook -from functools import wraps from typing import Any @@ -140,51 +138,3 @@ def human_readable_time_from_ns(ns: int) -> str: time_parts.insert(0, "%d%s" % (p, unit)) if ns == 0: return ", ".join(time_parts) - - -def cache(func): - saved = {} - - @wraps(func) - def new_func(*args): - if args in saved: - return saved[args] - - result = func(*args) - saved[args] = result - return result - - return new_func - - -@hook(list) -def intersection(self, *args) -> list: - ret = set(self).intersection(*args) - return list(ret) - - -@hook(list) -def __and__(self, *args) -> list: - return self.intersection(*args) - - -@hook(str) -def intersection(self, *args) -> str: - ret = set(self).intersection(*args) - return "".join(list(ret)) - - -@hook(str) -def __and__(self, *args) -> str: - return self.intersection(*args) - - -@hook(int) -def sum_digits(self) -> int: - s = 0 - num = self - while num > 0: - s += num % 10 - num //= 10 - - return s diff --git a/src/tools/types.py b/src/tools/types.py new file mode 100644 index 0000000..68c652c --- /dev/null +++ b/src/tools/types.py @@ -0,0 +1,20 @@ +from __future__ import annotations +from collections.abc import Iterable + + +class Integer(int): + def digits(self) -> Iterable[int]: + for x in str(self): + yield int(x) + + def digits_sum(self) -> int: + return sum(int(x) for x in str(self)) + + +class String(str): + def swap(self, x: int, y: int) -> String: + return String(self[:x] + self[y] + self[x + 1 : y] + self[x] + self[y + 1 :]) + + +class List(list): + pass