cobweb-launcher 1.3.4__tar.gz → 1.3.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/PKG-INFO +1 -1
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/launchers/__init__.py +1 -1
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/launchers/launcher_api.py +1 -1
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/utils/__init__.py +1 -1
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb_launcher.egg-info/PKG-INFO +1 -1
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb_launcher.egg-info/SOURCES.txt +0 -32
- cobweb-launcher-1.3.6/cobweb_launcher.egg-info/top_level.txt +1 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/setup.py +1 -1
- cobweb-launcher-1.3.4/cobweb_/__init__.py +0 -2
- cobweb-launcher-1.3.4/cobweb_/base/__init__.py +0 -9
- cobweb-launcher-1.3.4/cobweb_/base/common_queue.py +0 -30
- cobweb-launcher-1.3.4/cobweb_/base/decorators.py +0 -40
- cobweb-launcher-1.3.4/cobweb_/base/item.py +0 -46
- cobweb-launcher-1.3.4/cobweb_/base/log.py +0 -94
- cobweb-launcher-1.3.4/cobweb_/base/request.py +0 -82
- cobweb-launcher-1.3.4/cobweb_/base/response.py +0 -23
- cobweb-launcher-1.3.4/cobweb_/base/seed.py +0 -114
- cobweb-launcher-1.3.4/cobweb_/constant.py +0 -94
- cobweb-launcher-1.3.4/cobweb_/crawlers/__init__.py +0 -1
- cobweb-launcher-1.3.4/cobweb_/crawlers/crawler.py +0 -184
- cobweb-launcher-1.3.4/cobweb_/db/__init__.py +0 -2
- cobweb-launcher-1.3.4/cobweb_/db/api_db.py +0 -82
- cobweb-launcher-1.3.4/cobweb_/db/redis_db.py +0 -130
- cobweb-launcher-1.3.4/cobweb_/exceptions/__init__.py +0 -1
- cobweb-launcher-1.3.4/cobweb_/exceptions/oss_db_exception.py +0 -28
- cobweb-launcher-1.3.4/cobweb_/launchers/__init__.py +0 -3
- cobweb-launcher-1.3.4/cobweb_/launchers/launcher.py +0 -235
- cobweb-launcher-1.3.4/cobweb_/launchers/launcher_air.py +0 -88
- cobweb-launcher-1.3.4/cobweb_/launchers/launcher_api.py +0 -221
- cobweb-launcher-1.3.4/cobweb_/launchers/launcher_pro.py +0 -222
- cobweb-launcher-1.3.4/cobweb_/pipelines/__init__.py +0 -3
- cobweb-launcher-1.3.4/cobweb_/pipelines/pipeline.py +0 -69
- cobweb-launcher-1.3.4/cobweb_/pipelines/pipeline_console.py +0 -22
- cobweb-launcher-1.3.4/cobweb_/pipelines/pipeline_loghub.py +0 -34
- cobweb-launcher-1.3.4/cobweb_/setting.py +0 -74
- cobweb-launcher-1.3.4/cobweb_/utils/__init__.py +0 -5
- cobweb-launcher-1.3.4/cobweb_/utils/bloom.py +0 -58
- cobweb-launcher-1.3.4/cobweb_/utils/dotting.py +0 -32
- cobweb-launcher-1.3.4/cobweb_/utils/oss.py +0 -94
- cobweb-launcher-1.3.4/cobweb_/utils/tools.py +0 -42
- cobweb-launcher-1.3.4/cobweb_launcher.egg-info/top_level.txt +0 -2
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/LICENSE +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/README.md +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/__init__.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/__init__.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/basic.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/common_queue.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/dotting.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/item.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/log.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/request.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/response.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/base/seed.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/constant.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/crawlers/__init__.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/crawlers/crawler.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/db/__init__.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/db/api_db.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/db/redis_db.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/exceptions/__init__.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/exceptions/oss_db_exception.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/launchers/launcher.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/launchers/launcher_air.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/launchers/launcher_pro.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/pipelines/__init__.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/pipelines/pipeline.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/pipelines/pipeline_console.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/pipelines/pipeline_loghub.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/schedulers/__init__.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/schedulers/scheduler_api.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/schedulers/scheduler_redis.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/setting.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/utils/bloom.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/utils/oss.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb/utils/tools.py +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb_launcher.egg-info/dependency_links.txt +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/cobweb_launcher.egg-info/requires.txt +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/setup.cfg +0 -0
- {cobweb-launcher-1.3.4 → cobweb-launcher-1.3.6}/test/test.py +0 -0
@@ -5,7 +5,7 @@ from cobweb.schedulers import ApiScheduler
|
|
5
5
|
from .launcher import Launcher
|
6
6
|
|
7
7
|
|
8
|
-
class
|
8
|
+
class LauncherApi(Launcher):
|
9
9
|
|
10
10
|
def __init__(self, task, project, custom_setting=None, **kwargs):
|
11
11
|
super().__init__(task, project, custom_setting, **kwargs)
|
@@ -36,38 +36,6 @@ cobweb/utils/__init__.py
|
|
36
36
|
cobweb/utils/bloom.py
|
37
37
|
cobweb/utils/oss.py
|
38
38
|
cobweb/utils/tools.py
|
39
|
-
cobweb_/__init__.py
|
40
|
-
cobweb_/constant.py
|
41
|
-
cobweb_/setting.py
|
42
|
-
cobweb_/base/__init__.py
|
43
|
-
cobweb_/base/common_queue.py
|
44
|
-
cobweb_/base/decorators.py
|
45
|
-
cobweb_/base/item.py
|
46
|
-
cobweb_/base/log.py
|
47
|
-
cobweb_/base/request.py
|
48
|
-
cobweb_/base/response.py
|
49
|
-
cobweb_/base/seed.py
|
50
|
-
cobweb_/crawlers/__init__.py
|
51
|
-
cobweb_/crawlers/crawler.py
|
52
|
-
cobweb_/db/__init__.py
|
53
|
-
cobweb_/db/api_db.py
|
54
|
-
cobweb_/db/redis_db.py
|
55
|
-
cobweb_/exceptions/__init__.py
|
56
|
-
cobweb_/exceptions/oss_db_exception.py
|
57
|
-
cobweb_/launchers/__init__.py
|
58
|
-
cobweb_/launchers/launcher.py
|
59
|
-
cobweb_/launchers/launcher_air.py
|
60
|
-
cobweb_/launchers/launcher_api.py
|
61
|
-
cobweb_/launchers/launcher_pro.py
|
62
|
-
cobweb_/pipelines/__init__.py
|
63
|
-
cobweb_/pipelines/pipeline.py
|
64
|
-
cobweb_/pipelines/pipeline_console.py
|
65
|
-
cobweb_/pipelines/pipeline_loghub.py
|
66
|
-
cobweb_/utils/__init__.py
|
67
|
-
cobweb_/utils/bloom.py
|
68
|
-
cobweb_/utils/dotting.py
|
69
|
-
cobweb_/utils/oss.py
|
70
|
-
cobweb_/utils/tools.py
|
71
39
|
cobweb_launcher.egg-info/PKG-INFO
|
72
40
|
cobweb_launcher.egg-info/SOURCES.txt
|
73
41
|
cobweb_launcher.egg-info/dependency_links.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
cobweb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
from collections import deque
|
2
|
-
|
3
|
-
|
4
|
-
class Queue:
|
5
|
-
|
6
|
-
def __init__(self):
|
7
|
-
self._queue = deque()
|
8
|
-
|
9
|
-
@property
|
10
|
-
def length(self) -> int:
|
11
|
-
return len(self._queue)
|
12
|
-
|
13
|
-
def push(self, data, left: bool = False, direct_insertion: bool = False):
|
14
|
-
try:
|
15
|
-
if not data:
|
16
|
-
return None
|
17
|
-
if not direct_insertion and any(isinstance(data, t) for t in (list, tuple)):
|
18
|
-
self._queue.extendleft(data) if left else self._queue.extend(data)
|
19
|
-
else:
|
20
|
-
self._queue.appendleft(data) if left else self._queue.append(data)
|
21
|
-
except AttributeError:
|
22
|
-
pass
|
23
|
-
|
24
|
-
def pop(self, left: bool = True):
|
25
|
-
try:
|
26
|
-
return self._queue.popleft() if left else self._queue.pop()
|
27
|
-
except IndexError:
|
28
|
-
return None
|
29
|
-
except AttributeError:
|
30
|
-
return None
|
@@ -1,40 +0,0 @@
|
|
1
|
-
from functools import wraps
|
2
|
-
|
3
|
-
|
4
|
-
# def check_redis_status(func):
|
5
|
-
# @wraps(func)
|
6
|
-
# def wrapper(*args, **kwargs):
|
7
|
-
# try:
|
8
|
-
# result = func(*args, **kwargs)
|
9
|
-
# except Exception:
|
10
|
-
# result = False
|
11
|
-
# return result
|
12
|
-
#
|
13
|
-
# return wrapper
|
14
|
-
|
15
|
-
|
16
|
-
def decorator_oss_db(exception, retries=3):
|
17
|
-
def decorator(func):
|
18
|
-
@wraps(func)
|
19
|
-
def wrapper(callback_func, *args, **kwargs):
|
20
|
-
result = None
|
21
|
-
for i in range(retries):
|
22
|
-
msg = None
|
23
|
-
try:
|
24
|
-
return func(callback_func, *args, **kwargs)
|
25
|
-
except Exception as e:
|
26
|
-
result = None
|
27
|
-
msg = e
|
28
|
-
finally:
|
29
|
-
if result:
|
30
|
-
return result
|
31
|
-
|
32
|
-
if i >= 2 and msg:
|
33
|
-
raise exception(msg)
|
34
|
-
|
35
|
-
return wrapper
|
36
|
-
|
37
|
-
return decorator
|
38
|
-
|
39
|
-
|
40
|
-
|
@@ -1,46 +0,0 @@
|
|
1
|
-
from .seed import Seed
|
2
|
-
from collections import namedtuple
|
3
|
-
|
4
|
-
|
5
|
-
class Item(type):
|
6
|
-
|
7
|
-
def __new__(cls, name, bases, dct):
|
8
|
-
new_class_instance = type.__new__(cls, name, bases, dct)
|
9
|
-
if name != "BaseItem":
|
10
|
-
table = getattr(new_class_instance, "__TABLE__")
|
11
|
-
fields = getattr(new_class_instance, "__FIELDS__")
|
12
|
-
new_class_instance.Data = namedtuple(table, fields)
|
13
|
-
return new_class_instance
|
14
|
-
|
15
|
-
|
16
|
-
class BaseItem(metaclass=Item):
|
17
|
-
|
18
|
-
__TABLE__ = ""
|
19
|
-
__FIELDS__ = ""
|
20
|
-
|
21
|
-
def __init__(self, seed: Seed, **kwargs):
|
22
|
-
self.seed = seed
|
23
|
-
|
24
|
-
data = {}
|
25
|
-
for key, value in kwargs.items():
|
26
|
-
if key not in self.__FIELDS__:
|
27
|
-
self.__setattr__(key, value)
|
28
|
-
else:
|
29
|
-
data[key] = value
|
30
|
-
|
31
|
-
self.data = self.Data(**data)
|
32
|
-
|
33
|
-
@property
|
34
|
-
def to_dict(self):
|
35
|
-
return self.data._asdict()
|
36
|
-
|
37
|
-
@property
|
38
|
-
def table(self):
|
39
|
-
return self.Data.__name__
|
40
|
-
|
41
|
-
|
42
|
-
class ConsoleItem(BaseItem):
|
43
|
-
|
44
|
-
__TABLE__ = "console"
|
45
|
-
__FIELDS__ = "data"
|
46
|
-
|
@@ -1,94 +0,0 @@
|
|
1
|
-
import logging
|
2
|
-
|
3
|
-
|
4
|
-
class ColorCodes:
|
5
|
-
# Text Reset
|
6
|
-
RESET = "\033[0m"
|
7
|
-
|
8
|
-
# Regular Colors
|
9
|
-
RED = "\033[31m"
|
10
|
-
GREEN = "\033[32m"
|
11
|
-
YELLOW = "\033[33m"
|
12
|
-
BLUE = "\033[34m"
|
13
|
-
PURPLE = "\033[35m"
|
14
|
-
CYAN = "\033[36m"
|
15
|
-
WHITE = "\033[37m"
|
16
|
-
|
17
|
-
# Bright Colors
|
18
|
-
BRIGHT_RED = "\033[91m"
|
19
|
-
BRIGHT_GREEN = "\033[92m"
|
20
|
-
BRIGHT_YELLOW = "\033[93m"
|
21
|
-
BRIGHT_BLUE = "\033[94m"
|
22
|
-
BRIGHT_PURPLE = "\033[95m"
|
23
|
-
BRIGHT_CYAN = "\033[96m"
|
24
|
-
BRIGHT_WHITE = "\033[97m"
|
25
|
-
|
26
|
-
# Background Colors
|
27
|
-
BG_RED = "\033[41m"
|
28
|
-
BG_GREEN = "\033[42m"
|
29
|
-
BG_YELLOW = "\033[43m"
|
30
|
-
BG_BLUE = "\033[44m"
|
31
|
-
BG_PURPLE = "\033[45m"
|
32
|
-
BG_CYAN = "\033[46m"
|
33
|
-
BG_WHITE = "\033[47m"
|
34
|
-
|
35
|
-
# Bright Background Colors
|
36
|
-
BG_BRIGHT_RED = "\033[101m"
|
37
|
-
BG_BRIGHT_GREEN = "\033[102m"
|
38
|
-
BG_BRIGHT_YELLOW = "\033[103m"
|
39
|
-
BG_BRIGHT_BLUE = "\033[104m"
|
40
|
-
BG_BRIGHT_PURPLE = "\033[105m"
|
41
|
-
BG_BRIGHT_CYAN = "\033[106m"
|
42
|
-
BG_BRIGHT_WHITE = "\033[107m"
|
43
|
-
|
44
|
-
# Text Styles
|
45
|
-
BOLD = "\033[1m"
|
46
|
-
DIM = "\033[2m"
|
47
|
-
ITALIC = "\033[3m"
|
48
|
-
UNDERLINE = "\033[4m"
|
49
|
-
BLINK = "\033[5m"
|
50
|
-
REVERSE = "\033[7m"
|
51
|
-
HIDDEN = "\033[8m"
|
52
|
-
|
53
|
-
|
54
|
-
class Log:
|
55
|
-
logging.getLogger('oss2.api').setLevel(logging.WARNING)
|
56
|
-
logging.basicConfig(
|
57
|
-
level=logging.INFO,
|
58
|
-
format=f'%(asctime)s %(name)s [%(filename)s:%(lineno)d %(funcName)s]'
|
59
|
-
f' %(levelname)s -> %(message)s'
|
60
|
-
)
|
61
|
-
log = logging.getLogger()
|
62
|
-
|
63
|
-
def set_log_name(self, name):
|
64
|
-
self.__class__.log = logging.getLogger(name)
|
65
|
-
|
66
|
-
@property
|
67
|
-
def debug(self):
|
68
|
-
return self.__class__.log.debug
|
69
|
-
|
70
|
-
@property
|
71
|
-
def info(self):
|
72
|
-
return self.__class__.log.info
|
73
|
-
|
74
|
-
@property
|
75
|
-
def warning(self):
|
76
|
-
return self.__class__.log.warning
|
77
|
-
|
78
|
-
@property
|
79
|
-
def exception(self):
|
80
|
-
return self.__class__.log.exception
|
81
|
-
|
82
|
-
@property
|
83
|
-
def error(self):
|
84
|
-
return self.__class__.log.error
|
85
|
-
|
86
|
-
@property
|
87
|
-
def critical(self):
|
88
|
-
return self.__class__.log.critical
|
89
|
-
|
90
|
-
|
91
|
-
logger = Log()
|
92
|
-
|
93
|
-
|
94
|
-
|
@@ -1,82 +0,0 @@
|
|
1
|
-
import random
|
2
|
-
import requests
|
3
|
-
|
4
|
-
|
5
|
-
class Request:
|
6
|
-
|
7
|
-
__REQUEST_ATTRS__ = {
|
8
|
-
"params",
|
9
|
-
"headers",
|
10
|
-
"cookies",
|
11
|
-
"data",
|
12
|
-
"json",
|
13
|
-
"files",
|
14
|
-
"auth",
|
15
|
-
"timeout",
|
16
|
-
"proxies",
|
17
|
-
"hooks",
|
18
|
-
"stream",
|
19
|
-
"verify",
|
20
|
-
"cert",
|
21
|
-
"allow_redirects",
|
22
|
-
}
|
23
|
-
|
24
|
-
def __init__(
|
25
|
-
self,
|
26
|
-
url,
|
27
|
-
seed,
|
28
|
-
random_ua=True,
|
29
|
-
check_status_code=True,
|
30
|
-
**kwargs
|
31
|
-
):
|
32
|
-
self.url = url
|
33
|
-
self.seed = seed
|
34
|
-
self.check_status_code = check_status_code
|
35
|
-
self.request_setting = {}
|
36
|
-
|
37
|
-
for k, v in kwargs.items():
|
38
|
-
if k in self.__class__.__REQUEST_ATTRS__:
|
39
|
-
self.request_setting[k] = v
|
40
|
-
continue
|
41
|
-
self.__setattr__(k, v)
|
42
|
-
|
43
|
-
if not getattr(self, "method", None):
|
44
|
-
self.method = "POST" if self.request_setting.get("data") or self.request_setting.get("json") else "GET"
|
45
|
-
|
46
|
-
if random_ua:
|
47
|
-
self._build_header()
|
48
|
-
|
49
|
-
@property
|
50
|
-
def _random_ua(self) -> str:
|
51
|
-
v1 = random.randint(4, 15)
|
52
|
-
v2 = random.randint(3, 11)
|
53
|
-
v3 = random.randint(1, 16)
|
54
|
-
v4 = random.randint(533, 605)
|
55
|
-
v5 = random.randint(1000, 6000)
|
56
|
-
v6 = random.randint(10, 80)
|
57
|
-
user_agent = (f"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_{v1}_{v2}) AppleWebKit/{v4}.{v3} "
|
58
|
-
f"(KHTML, like Gecko) Chrome/105.0.0.0 Safari/{v4}.{v3} Edg/105.0.{v5}.{v6}")
|
59
|
-
return user_agent
|
60
|
-
|
61
|
-
def _build_header(self) -> dict:
|
62
|
-
if not self.request_setting.get("headers"):
|
63
|
-
self.request_setting["headers"] = {"accept": "*/*", "user-agent": self._random_ua}
|
64
|
-
elif "user-agent" not in [key.lower() for key in self.request_setting["headers"].keys()]:
|
65
|
-
self.request_setting["headers"]["user-agent"] = self._random_ua
|
66
|
-
|
67
|
-
def download(self) -> requests.Response:
|
68
|
-
response = requests.request(self.method, self.url, **self.request_setting)
|
69
|
-
if self.check_status_code:
|
70
|
-
response.raise_for_status()
|
71
|
-
return response
|
72
|
-
|
73
|
-
@property
|
74
|
-
def to_dict(self):
|
75
|
-
_dict = self.__dict__.copy()
|
76
|
-
_dict.pop('url')
|
77
|
-
_dict.pop('seed')
|
78
|
-
_dict.pop('check_status_code')
|
79
|
-
_dict.pop('request_setting')
|
80
|
-
return _dict
|
81
|
-
|
82
|
-
|
@@ -1,23 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Response:
|
4
|
-
|
5
|
-
def __init__(
|
6
|
-
self,
|
7
|
-
seed,
|
8
|
-
response,
|
9
|
-
**kwargs
|
10
|
-
):
|
11
|
-
self.seed = seed
|
12
|
-
self.response = response
|
13
|
-
|
14
|
-
for k, v in kwargs.items():
|
15
|
-
self.__setattr__(k, v)
|
16
|
-
|
17
|
-
@property
|
18
|
-
def to_dict(self):
|
19
|
-
_dict = self.__dict__.copy()
|
20
|
-
_dict.pop('seed')
|
21
|
-
_dict.pop('response')
|
22
|
-
return _dict
|
23
|
-
|
@@ -1,114 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
import time
|
3
|
-
import hashlib
|
4
|
-
|
5
|
-
|
6
|
-
class SeedParams:
|
7
|
-
|
8
|
-
def __init__(self, retry, priority, seed_version, seed_status=None):
|
9
|
-
self.retry = retry or 0
|
10
|
-
self.priority = priority or 300
|
11
|
-
self.seed_version = seed_version or int(time.time())
|
12
|
-
self.seed_status = seed_status
|
13
|
-
|
14
|
-
|
15
|
-
class Seed:
|
16
|
-
|
17
|
-
__SEED_PARAMS__ = [
|
18
|
-
"retry",
|
19
|
-
"priority",
|
20
|
-
"seed_version",
|
21
|
-
"seed_status"
|
22
|
-
]
|
23
|
-
|
24
|
-
def __init__(
|
25
|
-
self,
|
26
|
-
seed,
|
27
|
-
sid=None,
|
28
|
-
retry=None,
|
29
|
-
priority=None,
|
30
|
-
seed_version=None,
|
31
|
-
seed_status=None,
|
32
|
-
**kwargs
|
33
|
-
):
|
34
|
-
if any(isinstance(seed, t) for t in (str, bytes)):
|
35
|
-
try:
|
36
|
-
item = json.loads(seed)
|
37
|
-
self._init_seed(item)
|
38
|
-
except json.JSONDecodeError:
|
39
|
-
self.__setattr__("url", seed)
|
40
|
-
elif isinstance(seed, dict):
|
41
|
-
self._init_seed(seed)
|
42
|
-
else:
|
43
|
-
raise TypeError(Exception(
|
44
|
-
f"seed type error, "
|
45
|
-
f"must be str or dict! "
|
46
|
-
f"seed: {seed}"
|
47
|
-
))
|
48
|
-
|
49
|
-
seed_params = {
|
50
|
-
"retry": retry,
|
51
|
-
"priority": priority,
|
52
|
-
"seed_version": seed_version,
|
53
|
-
"seed_status": seed_status,
|
54
|
-
}
|
55
|
-
|
56
|
-
if kwargs:
|
57
|
-
self._init_seed(kwargs)
|
58
|
-
seed_params.update({
|
59
|
-
k:v for k, v in kwargs.items()
|
60
|
-
if k in self.__SEED_PARAMS__
|
61
|
-
})
|
62
|
-
if sid or not getattr(self, "sid", None):
|
63
|
-
self._init_id(sid)
|
64
|
-
self.params = SeedParams(**seed_params)
|
65
|
-
|
66
|
-
def __getattr__(self, name):
|
67
|
-
return None
|
68
|
-
|
69
|
-
def __setitem__(self, key, value):
|
70
|
-
setattr(self, key, value)
|
71
|
-
|
72
|
-
def __getitem__(self, item):
|
73
|
-
return getattr(self, item)
|
74
|
-
|
75
|
-
def __str__(self):
|
76
|
-
return json.dumps(self.__dict__, ensure_ascii=False)
|
77
|
-
|
78
|
-
def __repr__(self):
|
79
|
-
chars = [f"{k}={v}" for k, v in self.__dict__.items()]
|
80
|
-
return f'{self.__class__.__name__}({", ".join(chars)})'
|
81
|
-
|
82
|
-
def _init_seed(self, seed_info:dict):
|
83
|
-
for k, v in seed_info.items():
|
84
|
-
if k not in self.__SEED_PARAMS__:
|
85
|
-
self.__setattr__(k, v)
|
86
|
-
|
87
|
-
def _init_id(self, sid):
|
88
|
-
if not sid:
|
89
|
-
sid = hashlib.md5(self.to_string.encode()).hexdigest()
|
90
|
-
self.__setattr__("sid", sid)
|
91
|
-
|
92
|
-
@property
|
93
|
-
def to_dict(self) -> dict:
|
94
|
-
seed = self.__dict__.copy()
|
95
|
-
if seed.get("params"):
|
96
|
-
del seed["params"]
|
97
|
-
return seed
|
98
|
-
|
99
|
-
@property
|
100
|
-
def to_string(self) -> str:
|
101
|
-
return json.dumps(
|
102
|
-
self.to_dict,
|
103
|
-
ensure_ascii=False,
|
104
|
-
separators=(",", ":")
|
105
|
-
)
|
106
|
-
|
107
|
-
@property
|
108
|
-
def get_all(self):
|
109
|
-
return json.dumps(
|
110
|
-
self.__dict__,
|
111
|
-
ensure_ascii=False,
|
112
|
-
separators=(",", ":")
|
113
|
-
)
|
114
|
-
|
@@ -1,94 +0,0 @@
|
|
1
|
-
|
2
|
-
class CrawlerModel:
|
3
|
-
|
4
|
-
default = "cobweb.crawlers.Crawler"
|
5
|
-
file_air = "cobweb.crawlers.FileCrawlerAir"
|
6
|
-
file_pro = "cobweb.crawlers.FileCrawlerPro"
|
7
|
-
|
8
|
-
|
9
|
-
class LauncherModel:
|
10
|
-
task = "launcher model: task"
|
11
|
-
resident = "launcher model: resident"
|
12
|
-
|
13
|
-
|
14
|
-
class DownloadModel:
|
15
|
-
common = "download model: common"
|
16
|
-
file = "download model: file"
|
17
|
-
|
18
|
-
|
19
|
-
class LogModel:
|
20
|
-
simple = "log model: simple"
|
21
|
-
common = "log model: common"
|
22
|
-
detailed = "log model: detailed"
|
23
|
-
|
24
|
-
|
25
|
-
class DealModel:
|
26
|
-
fail = "deal model: fail"
|
27
|
-
done = "deal model: done"
|
28
|
-
poll = "deal model: poll"
|
29
|
-
|
30
|
-
|
31
|
-
class LogTemplate:
|
32
|
-
|
33
|
-
console_item = """
|
34
|
-
----------------------- start - console pipeline -----------------
|
35
|
-
种子详情 \n{seed_detail}
|
36
|
-
解析详情 \n{parse_detail}
|
37
|
-
----------------------- end - console pipeline ------------------
|
38
|
-
"""
|
39
|
-
|
40
|
-
launcher_air_polling = """
|
41
|
-
----------------------- start - 轮训日志: {task} -----------------
|
42
|
-
内存队列
|
43
|
-
种子数: {doing_len}
|
44
|
-
待消费: {todo_len}
|
45
|
-
已消费: {done_len}
|
46
|
-
存储队列
|
47
|
-
待上传: {upload_len}
|
48
|
-
----------------------- end - 轮训日志: {task} ------------------
|
49
|
-
"""
|
50
|
-
|
51
|
-
launcher_pro_polling = """
|
52
|
-
----------------------- start - 轮训日志: {task} -----------------
|
53
|
-
内存队列
|
54
|
-
种子数: {doing_len}
|
55
|
-
待消费: {todo_len}
|
56
|
-
已消费: {done_len}
|
57
|
-
redis队列
|
58
|
-
种子数: {redis_seed_count}
|
59
|
-
待消费: {redis_todo_len}
|
60
|
-
消费中: {redis_doing_len}
|
61
|
-
存储队列
|
62
|
-
待上传: {upload_len}
|
63
|
-
----------------------- end - 轮训日志: {task} ------------------
|
64
|
-
"""
|
65
|
-
|
66
|
-
download_exception = """
|
67
|
-
----------------------- download exception -----------------------
|
68
|
-
种子详情 \n{detail}
|
69
|
-
种子参数
|
70
|
-
retry : {retry}
|
71
|
-
priority : {priority}
|
72
|
-
seed_version : {seed_version}
|
73
|
-
identifier : {identifier}
|
74
|
-
exception
|
75
|
-
msg : {exception}
|
76
|
-
------------------------------------------------------------------
|
77
|
-
"""
|
78
|
-
|
79
|
-
download_info = """
|
80
|
-
------------------------ download info ---------------------------
|
81
|
-
种子详情 \n{detail}
|
82
|
-
种子参数
|
83
|
-
retry : {retry}
|
84
|
-
priority : {priority}
|
85
|
-
seed_version : {seed_version}
|
86
|
-
identifier : {identifier}
|
87
|
-
response
|
88
|
-
status : {status} \n{response}
|
89
|
-
------------------------------------------------------------------
|
90
|
-
"""
|
91
|
-
|
92
|
-
@staticmethod
|
93
|
-
def log_info(item: dict) -> str:
|
94
|
-
return "\n".join([" " * 12 + f"{str(k).ljust(14)}: {str(v)}" for k, v in item.items()])
|
@@ -1 +0,0 @@
|
|
1
|
-
from .crawler import Crawler
|