commit dfca1928c1275f25373045d8286e1b45812a0464 Author: minglipro Date: Sun Aug 10 12:17:08 2025 +0800 a diff --git a/.idea/autofangche.iml b/.idea/autofangche.iml new file mode 100644 index 0000000..8f47036 --- /dev/null +++ b/.idea/autofangche.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..ae196a3 --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c7f70e1 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..a681110 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c52ffdc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1b9e5d6 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..ecf8d7b --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + { + "associatedIndex": 6 +} + + + + { + "keyToString": { + "Python.main.executor": "Run", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true", + "RunOnceActivity.git.unshallow": "true", + "git-widget-placeholder": "master", + "last_opened_file_path": "G:/data/python/autofangche", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + 1739327117909 + + + + + + + + + \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..2ee591a --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple" +verify_ssl = true +name = "pip_conf_index_global" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.11" +python_full_version = "3.11.9" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..7e2dc41 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,21 @@ +{ + "_meta": { + "hash": { + "sha256": "48def127af5914e0bb297b845ac275758feb6e1b89fc8529b834fb09717e192c" + }, + "pipfile-spec": 6, + "requires": { + "python_full_version": "3.11.9", + "python_version": "3.11" + }, + "sources": [ + { + "name": "pip_conf_index_global", + "url": "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": {} +} diff --git a/__pycache__/logger.cpython-311.pyc b/__pycache__/logger.cpython-311.pyc new file mode 100644 index 0000000..9519eb4 Binary files /dev/null and b/__pycache__/logger.cpython-311.pyc differ diff --git a/logger.py b/logger.py new file mode 100644 index 0000000..59a6973 --- /dev/null +++ b/logger.py @@ -0,0 +1,33 @@ +import datetime +import sys + +from loguru import logger + + +class stdout(object): + def write(self, message): + with open('log/' + datetime.datetime.now().strftime("%Y%m%d%H") + ".log", 'a', encoding='utf-8') as f: + f.write(message) + + + def flush(self): + pass + + +logger.remove(0) + + +def printtime(t): + logger.info(t) + return t + + +logger.add( + sys.stdout, + colorize=True, + format="[{time:%Y-%m-%d %H:%M:%S,%f}] [{process.name}/{thread.name}/{function}] [{level}] {message}", + ) +logger.add( + stdout(), + format="[{time:%Y-%m-%d %H:%M:%S,%f}] [{process.name}/{thread.name}/{function}] [{level}] {message}", + ) diff --git a/main.py b/main.py new file mode 100644 index 0000000..32188b7 --- /dev/null +++ b/main.py @@ -0,0 +1,80 @@ +import datetime +import os +import time + +from playwright import sync_api + +from requests import get + +from logger import logger + +os.makedirs("log", exist_ok=True) + +TOKENAPI = "/api/auth/hik/token" + +def TokenData(): + return get(f"https://lida.mingliqiye.com{TOKENAPI}") + +p = sync_api.sync_playwright().start() +browser = p.chromium.launch(channel="msedge", headless=False) +context = browser.new_context() + +cookies_data = [ + { + 'name': 'Admin-Token', + 'value': TokenData().json()['Data']['token'], + 'domain': 'lida.haikewulian.com', + 'path': '/', + 'expires': (datetime.datetime.now() + datetime.timedelta(days=1)).timestamp(), + 'httpOnly': False, + 'secure': False, + 'sameSite': 'Lax' + },{ + 'name': 'Auth', + 'value': 'eyJSZW1iZXJNZSI6eyJzdGF0ZSI6dHJ1ZSwidXNlcm5hbWUiOiJsaWRhIiwicGFzc3dvcmQiOiIwNTA2MDdqaCJ9LCJUb2tlbiI6eyJ0eXBlIjoiIiwiZGF0YSI6IiJ9fQ==', + 'domain': 'lida.mingliqiye.com', + 'path': '/', + 'expires': (datetime.datetime.now() + datetime.timedelta(days=1)).timestamp(), + 'httpOnly': False, + 'secure': False, + 'sameSite': 'Lax' + }, +] + +context.add_cookies(cookies_data) + +page = context.new_page() +page.goto("http://lida.haikewulian.com/weighthouse/poundList") + +def taigan(): + get("http://192.168.127.245:8184/gate-operate/?a=1&channelNo=CNZEQ070108WE06") + +def fangche(): + page.locator(".btn1").click() + time.sleep(0.1) + page.locator('button[class="el-button el-button--success el-button--medium"]').click() + print(page.locator('input[placeholder="请输入车牌号"]').text_content()) + pass + +fangche() +def bucai(): + page.locator(".btn2").click() + time.sleep(5) + pass +haiguanold = '' +while True: + time.sleep(1) + haiguan = page.locator('span[class="el-tooltip call-tip el-tag el-tag--medium el-tag--light"]').text_content() + if haiguan != haiguanold: + haiguanold = haiguan + logger.info(haiguan) + if "车辆状态错误:车辆当前状态为【已入场】" in haiguan: + fangche() + taigan() + elif "海关放行" in haiguan: + fangche() + elif "读取不到货物运输批次提单信息" in haiguan: + fangche() + taigan() + elif "过卡车辆称重与申报空车重量不符:过卡车辆称重与申报空车重量不符" in haiguan: + bucai()