commit 6a4904ebb3271c90743a2271a0ade6d6ae7881bf Author: gorojack <1937047112@qq.com> Date: Thu Jul 18 18:08:24 2024 +0800 init project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..abdd4be --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# 小新记账订阅模板 + +### 规则编写 +APP对应规则写在apps目录下 + +- 文件名格式为包名点分割末尾字符 + +### 生成订阅JSON文件 +``` +python main.py +``` + +生成完毕之后目标JSON文件在`dist`目录,文件名格式为`${VERSION}.json` diff --git a/apps/hhjapp.py b/apps/hhjapp.py new file mode 100644 index 0000000..3d2e397 --- /dev/null +++ b/apps/hhjapp.py @@ -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": "", + }, + ], +} diff --git a/dist/0.0.1_alpha.json b/dist/0.0.1_alpha.json new file mode 100644 index 0000000..0d26a5a --- /dev/null +++ b/dist/0.0.1_alpha.json @@ -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": "自动填充内容" + } + ] + } + } + } +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..9f697e9 --- /dev/null +++ b/main.py @@ -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() diff --git a/subscription.py b/subscription.py new file mode 100644 index 0000000..9b0b7c8 --- /dev/null +++ b/subscription.py @@ -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))