xiao.qiang 8 hónapja
szülő
commit
ed76051ca4
4 módosított fájl, 41 hozzáadás és 13 törlés
  1. 20 0
      .gitignore
  2. 1 4
      test/deepcoin.py
  3. 2 2
      test/deepcoin_point.py
  4. 18 7
      utils/utils.py

+ 20 - 0
.gitignore

@@ -106,3 +106,23 @@ com_crashlytics_export_strings.xml
 crashlytics.properties
 crashlytics-build.properties
 
+/.venv/bin/activate
+/.venv/bin/activate.csh
+/.venv/bin/activate.fish
+/.venv/bin/Activate.ps1
+/.venv/bin/fastapi
+/.venv/bin/normalizer
+/.venv/bin/pip
+/.venv/bin/pip3
+/.venv/bin/pip3.10
+/.venv/bin/python
+/.venv/bin/python3
+/.venv/bin/python3.10
+/.venv/bin/readelf.py
+/.venv/bin/uiautomator2
+/.venv/bin/weditor
+/.venv/lib64/
+/.venv/pyvenv.cfg
+/.venv/lib64/
+/poetry.lock
+/.venv/lib64/

+ 1 - 4
test/deepcoin.py

@@ -8,7 +8,7 @@ from utils.utils import UiFactory
 ui = UiFactory('127.0.0.1:6555')
 # 从配置中加载坐标
 # 执行deepcoin_point.py 文件进行采集。
-ui.load_point()
+ui.load_point("deepcion_point.json")
 
 is_start = ui.check_app_running("com.niocpeed.dna")
 # tab 交易按钮
@@ -26,9 +26,6 @@ input_num = ui.xpath('input_num')
 # 设置数量
 btn_ping = ui.xpath('btn_ping')
 
-
-
-
 start1 = time.time()
 input_num.clear()
 end1 = time.time()

+ 2 - 2
test/deepcoin_point.py

@@ -12,8 +12,8 @@ btn_jy = ui.xpath("btn_jy", '//*[@content-desc="交易"]')
 input_weituo = ui.xpath("input_weituo", '//*[@content-desc="最优"]')
 # 设置数量
 # 设置数量
-input_num = ui.xpath('input_num','//android.widget.EditText')
+input_num = ui.xpath('input_num', '//android.widget.EditText')
 
 btn_buy = ui.desc("btn_buy", "买入/开多")
 
-ui.save_point()
+ui.save_point("deepcion_point.json")

+ 18 - 7
utils/utils.py

@@ -1,6 +1,4 @@
 import json
-import this
-import time
 
 import uiautomator2 as u2
 
@@ -68,6 +66,13 @@ class UiElement(object):
 
 
 class UiFactory(object):
+    """
+    这个类对 u2.connect 的几个方法做了封装,主要解决耗时问题。
+    并且做缓存。不重复定位。
+
+    可以使用 load_point 方法 加载 xxx_point.json中,已经配置好的坐标。
+    """
+
     _cache = {}
 
     def __init__(self, serial: str):
@@ -80,8 +85,9 @@ class UiFactory(object):
 
     def xpath(self, alisa: str, xpath: str = None):
         """
-        通过 xpath获取坐标
+        通过 xpath获取元素
         alisa 别名
+        xpath  如果别名没有获取缓存, 会通过xpath 重新定位,并且缓存
         """
         if alisa in self._cache:
             return self._cache[alisa]
@@ -93,6 +99,11 @@ class UiFactory(object):
         return el
 
     def desc(self, alisa: str, desc: str = None):
+        """
+        通过文本获取元素
+        alisa 别名
+        desc 如果别名没有获取缓存, 会通过description 重新定位,并且缓存
+        """
         if alisa in self._cache:
             return self._cache[alisa]
 
@@ -102,9 +113,9 @@ class UiFactory(object):
 
         return el
 
-    def load_point(self):
+    def load_point(self, point_json: str):
         __tmp__ = {}
-        with open("deepcion_point.json", "r", encoding="utf-8") as f:
+        with open(point_json, "r", encoding="utf-8") as f:
             __tmp__ = json.load(f)
 
         for k, v in __tmp__.items():
@@ -113,7 +124,7 @@ class UiFactory(object):
             elif 'description' in v:
                 self._cache[k] = UiElement(self.d, description=v['description'], point=v['point'])
 
-    def save_point(self):
+    def save_point(self, point_json: str):
         """
         保存坐标
         """
@@ -121,7 +132,7 @@ class UiFactory(object):
         for k, v in self._cache.items():
             __tmp__[k] = v.info
 
-        with open("deepcion_point.json", "w", encoding="utf-8") as f:
+        with open(point_json, "w", encoding="utf-8") as f:
             json.dump(__tmp__, f, ensure_ascii=False, indent=4)
 
     def check_app_running(self, appid: str):