init project

This commit is contained in:
gorojack 2024-07-18 18:08:24 +08:00
commit 6a4904ebb3
6 changed files with 152 additions and 0 deletions

1
.gitignore vendored Normal file

@ -0,0 +1 @@
__pycache__

13
README.md Normal file

@ -0,0 +1,13 @@
# 小新记账订阅模板
### 规则编写
APP对应规则写在apps目录下
- 文件名格式为包名点分割末尾字符
### 生成订阅JSON文件
```
python main.py
```
生成完毕之后目标JSON文件在`dist`目录,文件名格式为`${VERSION}.json`

29
apps/hhjapp.py Normal file

@ -0,0 +1,29 @@
hhjapp = {
"packageName": "tech.cqxqg.hhjapp",
"name": "小新记账",
"version": "1.0.0",
"rules": [
{
"key": 0,
"selector": "[text='记账']",
"action": "click",
},
{
"key": 1,
"selector": "[desc='备注'] + Button + EditText",
"action": "click",
"actionDelay": 50,
"activityId": "tech.cqxqg.hhjapp.MainActivity",
"classId": "",
},
{
"key": 2,
"selecotr": "[desc='备注'] + Button + EditText]",
"preAction": 1,
"action": "setText",
"args": "自动填充内容",
"activityId": "tech.cqxqg.hhjapp.MainActivity",
"classId": "",
},
],
}

32
dist/0.0.1_alpha.json vendored Normal file

@ -0,0 +1,32 @@
{
"version": "0.0.1_alpha",
"apps": {
"hhjapp": {
"hhjapp": {
"packageName": "tech.cqxqg.hhjapp",
"name": "小新记账",
"version": "1.0.0",
"rules": [
{
"key": 0,
"selector": "[text='记账']",
"action": "click"
},
{
"key": 1,
"selector": "[desc='备注'] + Button + EditText",
"action": "click",
"actionDelay": 50
},
{
"key": 2,
"selecotr": "[desc='备注'] + Button + EditText]",
"preAction": 1,
"action": "setText",
"args": "自动填充内容"
}
]
}
}
}
}

30
main.py Normal file

@ -0,0 +1,30 @@
import os
import json
from subscription import get_subscription, version
targetFile = "dist/%s.json" % version
def main():
print(
"""
------------------------------------------------------
\tGenerating subscription.json
------------------------------------------------------
"""
)
os.makedirs(os.path.dirname(targetFile), exist_ok=True)
with open(targetFile, "w", encoding="utf-8") as f:
json.dump(get_subscription(), f, ensure_ascii=False, indent=4)
print(
"""
------------------------------------------------------
\tDone
------------------------------------------------------
"""
)
if __name__ == "__main__":
main()

47
subscription.py Normal file

@ -0,0 +1,47 @@
import importlib.util
import os
version = "0.0.1_alpha"
def get_subscription():
apps_folder = "apps"
apps = get_global_vars_from_apps(apps_folder)
return {
"version": version,
"apps": apps,
}
def get_global_vars_from_apps(apps_folder):
global_vars = {}
for filename in os.listdir(apps_folder):
if filename.endswith(".py"):
module_name = filename[:-3]
file_path = os.path.join(apps_folder, filename)
spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
module_globals = {
key: value
for key, value in vars(module).items()
if not key.startswith("__")
}
print(
"Scanned packageName: %s" % module_globals[module_name]["packageName"]
)
global_vars[module_name] = module_globals
return global_vars
if __name__ == "__main__":
apps_folder = "apps"
apps = get_global_vars_from_apps(apps_folder)
print(apps)
for app, info in apps:
print("%s: %s" % (app, info))