coocan 0.4.5__tar.gz → 0.4.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.
- {coocan-0.4.5 → coocan-0.4.6}/PKG-INFO +1 -1
- coocan-0.4.6/coocan/cmd/cli.py +66 -0
- coocan-0.4.5/coocan/cmd/templates/spider.py → coocan-0.4.6/coocan/cmd/templates/spider.txt +6 -1
- {coocan-0.4.5 → coocan-0.4.6}/coocan.egg-info/PKG-INFO +1 -1
- {coocan-0.4.5 → coocan-0.4.6}/coocan.egg-info/SOURCES.txt +1 -2
- {coocan-0.4.5 → coocan-0.4.6}/setup.py +6 -2
- coocan-0.4.5/coocan/cmd/cli.py +0 -41
- coocan-0.4.5/coocan/cmd/templates/__init__.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/__init__.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/cmd/__init__.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/gen.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/spider/__init__.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/spider/base.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/url/__init__.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/url/request.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan/url/response.py +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan.egg-info/dependency_links.txt +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan.egg-info/entry_points.txt +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan.egg-info/requires.txt +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/coocan.egg-info/top_level.txt +0 -0
- {coocan-0.4.5 → coocan-0.4.6}/setup.cfg +0 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
import re
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
import click
|
5
|
+
|
6
|
+
TEMPLATE_DIR = Path(__file__).parent / "templates"
|
7
|
+
|
8
|
+
help_info = """
|
9
|
+
██████╗ ██████╗ ██████╗ ██████╗ █████╗ ███╗ ██╗
|
10
|
+
██╔════╝██╔═══██╗██╔═══██╗██╔════╝██╔══██╗████╗ ██║
|
11
|
+
██║ ██║ ██║██║ ██║██║ ███████║██╔██╗ ██║
|
12
|
+
██║ ██║ ██║██║ ██║██║ ██╔══██║██║╚██╗██║
|
13
|
+
╚██████╗╚██████╔╝╚██████╔╝╚██████╗██║ ██║██║ ╚████║
|
14
|
+
╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═══╝
|
15
|
+
"""
|
16
|
+
|
17
|
+
|
18
|
+
def show_help_info():
|
19
|
+
print(help_info)
|
20
|
+
|
21
|
+
|
22
|
+
def snake_to_pascal(snake_str: str):
|
23
|
+
"""小蛇变成大驼峰"""
|
24
|
+
words = snake_str.split('_')
|
25
|
+
pascal_str = ''.join(word.capitalize() for word in words)
|
26
|
+
return pascal_str
|
27
|
+
|
28
|
+
|
29
|
+
@click.group(invoke_without_command=True) # 允许无子命令调用
|
30
|
+
@click.pass_context
|
31
|
+
def main(ctx):
|
32
|
+
if ctx.invoked_subcommand is None:
|
33
|
+
show_help_info()
|
34
|
+
click.echo("cc new -s <spider_file_name>")
|
35
|
+
|
36
|
+
|
37
|
+
@main.command()
|
38
|
+
@click.option('-s', '--spider', required=True, help='爬虫文件名字')
|
39
|
+
def new(spider):
|
40
|
+
"""新建"""
|
41
|
+
if not re.search("^[a-zA-Z0-9_]*$", spider):
|
42
|
+
click.echo("只支持字母、数字、下划线")
|
43
|
+
return
|
44
|
+
|
45
|
+
pascal = snake_to_pascal(spider)
|
46
|
+
if not pascal.endswith("Spider"):
|
47
|
+
pascal += "Spider"
|
48
|
+
|
49
|
+
try:
|
50
|
+
template_path = TEMPLATE_DIR / "spider.txt"
|
51
|
+
with open(template_path, 'r') as f:
|
52
|
+
text = f.read()
|
53
|
+
spider_py_text = text.replace("{SpiderClassName}", pascal)
|
54
|
+
|
55
|
+
with open("{}.py".format(spider), 'w') as f:
|
56
|
+
f.write(spider_py_text)
|
57
|
+
|
58
|
+
click.echo("Success")
|
59
|
+
|
60
|
+
except Exception as e:
|
61
|
+
click.echo(str(e))
|
62
|
+
raise click.ClickException("Failed")
|
63
|
+
|
64
|
+
|
65
|
+
if __name__ == '__main__':
|
66
|
+
main()
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from coocan import Request, Response, MiniSpider
|
2
2
|
|
3
3
|
|
4
|
-
class
|
4
|
+
class {SpiderClassName}(MiniSpider):
|
5
5
|
start_urls = ['https://github.com/markadc/coocan']
|
6
6
|
max_requests = 10
|
7
7
|
|
@@ -10,3 +10,8 @@ class Spider(MiniSpider):
|
|
10
10
|
|
11
11
|
def parse(self, response: Response):
|
12
12
|
pass
|
13
|
+
|
14
|
+
|
15
|
+
if __name__ == '__main__':
|
16
|
+
s = {SpiderClassName}()
|
17
|
+
s.go()
|
@@ -9,8 +9,7 @@ coocan.egg-info/requires.txt
|
|
9
9
|
coocan.egg-info/top_level.txt
|
10
10
|
coocan/cmd/__init__.py
|
11
11
|
coocan/cmd/cli.py
|
12
|
-
coocan/cmd/templates/
|
13
|
-
coocan/cmd/templates/spider.py
|
12
|
+
coocan/cmd/templates/spider.txt
|
14
13
|
coocan/spider/__init__.py
|
15
14
|
coocan/spider/base.py
|
16
15
|
coocan/url/__init__.py
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name="coocan",
|
5
|
-
version="0.4.
|
5
|
+
version="0.4.6",
|
6
6
|
author="wauo",
|
7
7
|
author_email="markadc@126.com",
|
8
8
|
description="Air Spider Framework",
|
@@ -15,5 +15,9 @@ setup(
|
|
15
15
|
'console_scripts': [
|
16
16
|
'cc=coocan.cmd.cli:main',
|
17
17
|
],
|
18
|
-
}
|
18
|
+
},
|
19
|
+
package_data={
|
20
|
+
'coocan.cmd': ['templates/*'],
|
21
|
+
},
|
22
|
+
include_package_data=True
|
19
23
|
)
|
coocan-0.4.5/coocan/cmd/cli.py
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
from pathlib import Path
|
2
|
-
|
3
|
-
import click
|
4
|
-
|
5
|
-
TEMPLATE_DIR = Path(__file__).parent / "templates"
|
6
|
-
|
7
|
-
|
8
|
-
@click.group()
|
9
|
-
def main():
|
10
|
-
"""
|
11
|
-
\n
|
12
|
-
可用命令:
|
13
|
-
new - 创建新的爬虫文件
|
14
|
-
\n
|
15
|
-
示例:
|
16
|
-
cc new -s demo
|
17
|
-
"""
|
18
|
-
|
19
|
-
|
20
|
-
@main.command()
|
21
|
-
@click.option('-s', '--spider', required=True, help='爬虫文件')
|
22
|
-
def new(spider):
|
23
|
-
"""新建"""
|
24
|
-
spider_file_name = "{}.py".format(spider)
|
25
|
-
try:
|
26
|
-
template_path = TEMPLATE_DIR / "spider.py"
|
27
|
-
with open(template_path, 'r') as f:
|
28
|
-
content = f.read()
|
29
|
-
|
30
|
-
with open(spider_file_name, 'w') as f:
|
31
|
-
f.write(content)
|
32
|
-
|
33
|
-
click.echo("Success")
|
34
|
-
|
35
|
-
except Exception as e:
|
36
|
-
click.echo(str(e))
|
37
|
-
raise click.ClickException("Failed")
|
38
|
-
|
39
|
-
|
40
|
-
if __name__ == '__main__':
|
41
|
-
main()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|