Browse Source

优化项目结构

liuyuqi-dellpc 1 year ago
parent
commit
0f1f9eac98
11 changed files with 140 additions and 74 deletions
  1. 1 0
      .gitignore
  2. 6 0
      bin/crawl_hero
  3. 15 0
      crawl_hero/__init__.py
  4. 13 0
      crawl_hero/api.py
  5. 67 0
      crawl_hero/crawl_hero.py
  6. 3 0
      crawl_hero/version.py
  7. 12 0
      docs/Development.md
  8. 10 0
      game.gtimg.cn.http
  9. 0 73
      getHero.py
  10. 1 1
      getHero.spec
  11. 12 0
      main.py

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 /build/getHero
 /build/getHero
 /__pycache__
 /__pycache__
+*.pyc

+ 6 - 0
bin/crawl_hero

@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+import crawl_hero
+
+if __name__ == '__main__':
+    crawl_hero.main()

+ 15 - 0
crawl_hero/__init__.py

@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/05/24 13:07:28
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   main function
+'''
+import time
+from crawl_hero.crawl_hero import CrawlHero
+
+
+def main(argv=None):
+    crawl = CrawlHero()
+    crawl.getHero()

+ 13 - 0
crawl_hero/api.py

@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/05/24 15:02:12
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   api
+'''
+
+_host = r"https://game.gtimg.cn"
+
+hero_list_url = _host+"/images/lol/act/img/js/heroList/hero_list.js"
+hero_img_url = _host+ "/images/lol/act/img/js/hero/%s.js"

+ 67 - 0
crawl_hero/crawl_hero.py

@@ -0,0 +1,67 @@
+import requests
+import os
+from crawl_hero import api
+
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/03/08 21:12:55
+@License :   Copyright © 2017-2020 liuyuqi. All Rights Reserved.
+@Desc    :   
+
+# 2. 编写一个工具(LOL皮肤下载工具) ----封装的思想
+#   给用户展示所有的英雄名称和id (在控制台输出 所有英雄的名称和id  每三个为一行)
+#   用户输入想要的英雄皮肤   (用户输入所需要的英雄id)
+#   如果有,则进行下载,      判断id是否在英雄id列表中存在
+#   如果没有让用户从新输入    y 继续数据皮肤信息    n 输出程序结束
+'''
+
+class CrawlHero():
+
+    def __init__(self):
+        self.s = requests.Session()
+        self.hero_id_list = []
+
+    def getHeroId(self):
+        response = self.s.get(api.hero_list_url).json()
+        hero_list = response["hero"]
+        print("-----------所有英雄id和名字--------------------")
+        input("按任意键继续")
+        index = 1
+        tmp = ""
+        for hero in hero_list:
+            tmp = tmp + hero["heroId"] + " " + hero["name"] + "    "
+            if index % 3 == 0:
+                print(tmp)
+                tmp = ""
+            self.hero_id_list.append(hero["heroId"])
+            index = index + 1
+
+    def getHeroPic(self):
+        while(1):
+            mHeroId = input("用户输入所需要的英雄id:")
+        # 获取所有英雄图片的地址
+            for hero_id in self.hero_id_list:
+                if mHeroId == hero_id:
+                    hero_img_url = api.hero_img_url % (hero_id)
+                    skin_list = self.s.get(hero_img_url).json()["skins"]
+                    for skin in skin_list:
+                        mainImg = skin["mainImg"]
+                        heroName = skin["heroName"]
+                        name = skin["name"]
+                        if not os.path.exists(heroName):
+                            os.mkdir(heroName)
+                        if mainImg == "":
+                            with open(heroName + "/" + name + ".jpg", "wb") as file:
+                                file.write(self.s.get(
+                                    skin["chromaImg"]).content)
+                        else:
+                            with open(heroName + "/" + name + ".jpg", "wb") as file:
+                                file.write(self.s.get(skin["mainImg"]).content)
+            print("下载结束,头像保存至当前目录\r\n\r\n")
+            yn = input("y 继续    n 输出程序结束:")
+            if yn == "n":
+                exit()
+
+    def getHero(self):
+        self.getHeroId()
+        self.getHeroPic()

+ 3 - 0
crawl_hero/version.py

@@ -0,0 +1,3 @@
+from __future__ import unicode_literals
+
+__version__ = '2022.05.24'

+ 12 - 0
docs/Development.md

@@ -0,0 +1,12 @@
+## Development
+
+```
+
+virtualenv .venv 
+
+pip install -r requirements.txt
+
+pip install pyinstaller
+pyinstaller -F -c  getHero.py
+
+```

+ 10 - 0
game.gtimg.cn.http

@@ -0,0 +1,10 @@
+### 全局变量
+@hostname = game.gtimg.cn
+@host = https://{{hostname}}
+@contentType = application/x-www-form-urlencoded;charset=utf-8; charset=utf-8
+@cookie=xx; Path=/
+
+### 英雄列表
+GET {{host}}/images/lol/act/img/js/heroList/hero_list.js HTTP/1.1
+Cookie: {{cookie}}
+Content-Type: {{contentType}}

+ 0 - 73
getHero.py

@@ -1,73 +0,0 @@
-import requests
-import os
-
-'''
-@Contact :   liuyuqi.gov@msn.cn
-@Time    :   2022/03/08 21:12:55
-@License :   Copyright © 2017-2020 liuyuqi. All Rights Reserved.
-@Desc    :   
-
-# 2. 编写一个工具(LOL皮肤下载工具) ----封装的思想
-#   给用户展示所有的英雄名称和id (在控制台输出 所有英雄的名称和id  每三个为一行)
-#   用户输入想要的英雄皮肤   (用户输入所需要的英雄id)
-#   如果有,则进行下载,      判断id是否在英雄id列表中存在
-#   如果没有让用户从新输入    y 继续数据皮肤信息    n 输出程序结束
-'''
-
-
-hero_list_url = "https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js"
-s = requests.Session()
-hero_id_list = []
-
-
-def getHeroId():
-    global hero_id_list
-    response = s.get(hero_list_url).json()
-    hero_list = response["hero"]
-    print("-----------所有英雄id和名字--------------------")
-    input("按任意键继续")
-    index = 1
-    tmp = ""
-    for hero in hero_list:
-        tmp = tmp + hero["heroId"] + " " + hero["name"] + "    "
-        if index % 3 == 0:
-            print(tmp)
-            tmp = ""
-        hero_id_list.append(hero["heroId"])
-        index = index + 1
-
-
-def getHeroPic():
-    while(1):
-        mHeroId = input("用户输入所需要的英雄id:")
-      # 获取所有英雄图片的地址
-        for hero_id in hero_id_list:
-            if mHeroId == hero_id:
-                hero_img_url = "https://game.gtimg.cn/images/lol/act/img/js/hero/%s.js" % (
-                    hero_id)
-                skin_list = s.get(hero_img_url).json()["skins"]
-                for skin in skin_list:
-                    mainImg = skin["mainImg"]
-                    heroName = skin["heroName"]
-                    name = skin["name"]
-                    if not os.path.exists(heroName):
-                        os.mkdir(heroName)
-                    if mainImg == "":
-                        with open(heroName + "/" + name + ".jpg", "wb") as file:
-                            file.write(s.get(skin["chromaImg"]).content)
-                    else:
-                        with open(heroName + "/" + name + ".jpg", "wb") as file:
-                            file.write(s.get(skin["mainImg"]).content)
-        print("下载结束,头像保存至当前目录\r\n\r\n")
-        yn = input("y 继续    n 输出程序结束:")
-        if yn == "n":
-            exit()
-
-
-def getHero():
-    getHeroId()
-    getHeroPic()
-
-
-if __name__ == '__main__':
-    getHero()

+ 1 - 1
getHero.spec

@@ -4,7 +4,7 @@
 block_cipher = None
 block_cipher = None
 
 
 
 
-a = Analysis(['getHero.py'],
+a = Analysis(['main.py'],
              pathex=[],
              pathex=[],
              binaries=[],
              binaries=[],
              datas=[],
              datas=[],

+ 12 - 0
main.py

@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+'''
+@Contact :   liuyuqi.gov@msn.cn
+@Time    :   2022/05/23 14:33:19
+@License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
+@Desc    :   main
+'''
+import crawl_hero
+
+if __name__ == '__main__':
+    crawl_hero.main()