coocan 0.4.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: coocan
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: Air Spider Framework
5
5
  Author: wauo
6
6
  Author-email: markadc@126.com
@@ -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 Spider(MiniSpider):
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: coocan
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: Air Spider Framework
5
5
  Author: wauo
6
6
  Author-email: markadc@126.com
@@ -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/__init__.py
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
@@ -1 +1,3 @@
1
1
  click>=8.0.0
2
+ httpx
3
+ loguru
@@ -2,18 +2,22 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="coocan",
5
- version="0.4.4",
5
+ version="0.4.6",
6
6
  author="wauo",
7
7
  author_email="markadc@126.com",
8
8
  description="Air Spider Framework",
9
9
  packages=find_packages(),
10
10
  python_requires=">=3.10",
11
11
  install_requires=[
12
- 'click>=8.0.0',
12
+ 'click>=8.0.0', 'httpx', 'loguru'
13
13
  ],
14
14
  entry_points={
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
  )
@@ -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
- \b
12
- 可用命令:
13
- new - 创建新的爬虫文件
14
- \b
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 create spider file {}".format(spider_file_name))
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