feat: add new_anime factory class method
parent
79074befe7
commit
f6eed8f18c
1
Pipfile
1
Pipfile
|
@ -11,3 +11,4 @@ twine = "*"
|
|||
sphinx = "*"
|
||||
sphinx-rtd-theme = "*"
|
||||
radon = "*"
|
||||
"flake8" = "*"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "f182f386e6ad648cfa47633b4e6b6e48511e18e06eb0f602c6d0b2c449e57ca7"
|
||||
"sha256": "457dc98718285d0b6166dc6acec90e416c6578bc88d2ecc12337a38848c863f3"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
|
@ -176,6 +176,7 @@
|
|||
"sha256:859996073f341f2670741b51ec1e67a01da142831aa1fdc6242dbf88dffbe661",
|
||||
"sha256:a796a115208f5c03b18f332f7c11729812c8c3ded6c46319c59b53efd3819da8"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.7.7"
|
||||
},
|
||||
"flake8-polyfill": {
|
||||
|
|
|
@ -7,6 +7,7 @@ from bs4 import BeautifulSoup
|
|||
import os
|
||||
import logging
|
||||
import copy
|
||||
import importlib
|
||||
|
||||
from anime_downloader.sites.exceptions import AnimeDLError, NotFoundError
|
||||
from anime_downloader import util
|
||||
|
@ -92,6 +93,24 @@ class Anime:
|
|||
def factory(cls, sitename: str):
|
||||
return cls.subclasses[sitename]
|
||||
|
||||
@classmethod
|
||||
def new_anime(cls, sitename: str):
|
||||
"""
|
||||
new_anime is a factory which returns the anime class corresposing to
|
||||
`sitename`
|
||||
|
||||
Returns
|
||||
-------
|
||||
subclass of Anime
|
||||
"""
|
||||
module = importlib.import_module(
|
||||
'anime_downloader.sites.{}'.format(sitename)
|
||||
)
|
||||
for c in dir(module):
|
||||
if issubclass(c, cls):
|
||||
return c
|
||||
raise ImportError("Cannot find subclass of {}".format(cls))
|
||||
|
||||
def get_data(self):
|
||||
"""
|
||||
get_data is called inside the :code:`__init__` of
|
||||
|
|
Loading…
Reference in New Issue