-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating plugins with inheritance #167
Labels
Comments
Plus two supporting methods to this class (these allways used): [spoiler] Code def pretty_printer(self, engine_url: str, name: str, link: str, size: str,
seeds: str, leech: str, desc_link: str = None):
size = str(self.any_size_to_bytes(size))
text = "|".join([link, name.replace("|", " "), size, seeds, leech,
engine_url] + [desc_link] if desc_link else [])
# fd 1 is stdout
with open(1, 'w', encoding='utf-8', closefd=False) as utf8stdout:
print(text, file=utf8stdout)
@staticmethod
def any_size_to_bytes(size_string: str):
"""
Convert a string like '1 KB' to '1024' (bytes)
Possible formats: 2.6Gb, 3,2 M, 5211564
"""
# separate integer from unit
size_string = size_string.strip()
if not size_string[0].isdigit():
return -1
try:
# get first literal
unit = ''.join(filter(str.isalpha, size_string))[0]
except IndexError:
return int(size_string)
size = size_string[:size_string.index(unit)].strip().replace(',', '.')
# convert
units_dict = {'T': 40, 'G': 30, 'M': 20, 'K': 10}
return int(float(size) * 2 ** units_dict.get(unit.upper(), 0)) |
I agree with this change but I think it will be difficult to implement for the following reasons:
I'm not very active in this project but I'm open to review and accept PR as long as they are backwards compatible. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was thinking a lot, how about base class for plugins?
[spoiler] Something like this...
It will help (i think) beginners to understand which attribute/method is required to implement.
Also, qbt developers will be able to manipulate some basic logic or engine behavior.
The text was updated successfully, but these errors were encountered: