Browse Source

fix error

fish 7 months ago
parent
commit
e1273ea9cd
6 changed files with 17 additions and 13 deletions
  1. 1 0
      .gitignore
  2. 0 1
      README.md
  3. 2 2
      crawl_yuque/__init__.py
  4. 5 2
      crawl_yuque/options.py
  5. 7 5
      crawl_yuque/yuque.py
  6. 2 3
      main.py

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 *.pyc
 build/
 dist/
+download/

+ 0 - 1
README.md

@@ -15,7 +15,6 @@ wget https://fileshare.yoqi.me/d/dl/c/Python/crawl_yuque/crawl_yuque
 chmod +x crawl_yuque
 ./crawl_yuque markdown -url https://www.yuque.com/burpheart/phpaudit
 
-https://www.yuque.com/yuque/thyzgp
 ```
 
 私有文档配置 .env 文件,chrome 获取cookie填入即可,登录状态可以看到的项目都可以获取。

+ 2 - 2
crawl_yuque/__init__.py

@@ -30,8 +30,8 @@ def main(argv=None):
             return
         if command == "markdown":
             crawl = YuQue(args)
-            if(args.url != ''):
-                url = args.url
+            if(args["url"] != ''):
+                url = args["url"]
                 crawl.get_book(url=url)
             else:
                 url = input("请输入语雀文档链接:")

+ 5 - 2
crawl_yuque/options.py

@@ -35,8 +35,11 @@ def parser_args(overrideArguments=None):
     system_conf = user_conf = custom_conf = OrderedDict()
     user_conf = _read_user_conf()
 
-    if args.config:
-        custom_conf = _read_custom_conf(args.config)
+    try:
+        if args.config:
+            custom_conf = _read_custom_conf(args.config)
+    except Exception as e:
+        pass
 
     system_conf.update(user_conf)
     system_conf.update(command_line_conf)

+ 7 - 5
crawl_yuque/yuque.py

@@ -19,7 +19,7 @@ from . import api
 class YuQue(object):
     ''' 语雀知识库下载 '''
     
-    def __init__(self):
+    def __init__(self, args):
         self.sess=requests.Session()
 
         self.logger = logging.getLogger(__name__)
@@ -30,10 +30,10 @@ class YuQue(object):
         self.ch.setFormatter(self.formatter)
         self.logger.addHandler(self.ch)
         
-        self.args = None
-        self.parser = argparse.ArgumentParser(description='yuque download')
-        self.parser.add_argument('-url', '--url', help='url', default='')
-        self.args = self.parser.parse_args()
+        # self.args = None
+        # self.parser = argparse.ArgumentParser(description='yuque download')
+        # self.parser.add_argument('-url', '--url', help='url', default='')
+        self.args = args
 
     def save_page(self, book_id, sulg, path):
         ''' 保存文档 '''
@@ -48,6 +48,7 @@ class YuQue(object):
 
     def get_book(self, url):
         ''' 获取知识库 '''
+        print("获取知识库 " + url + " download.........")
         try:
             docsdata = requests.get(url)
             data = re.findall(r"decodeURIComponent\(\"(.+)\"\)\);", docsdata.content.decode('utf-8'))
@@ -107,6 +108,7 @@ class YuQue(object):
                                 'title'].translate(table) + '.md')
         with open(f"{download_dir}" + "/SUMMARY.md", 'w', encoding='utf-8') as f:
             f.write(md)
+        print("finish.....")
 
     def pdf(self):
         """ 生成pdf """

+ 2 - 3
main.py

@@ -6,8 +6,7 @@
 @License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
 @Desc    :   enter point
 '''
-from crawl_yuque import YuQue
+from crawl_yuque import main
 
 if __name__=='__main__':
-    yuque = YuQue()
-    yuque.run()
+    main()