commit a176f2a7719da8215d0e46930a7cef906404165a Author: caoqianming Date: Wed Mar 8 09:10:28 2023 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ee6edb --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.exe +*.spec +venv/ +dist/ +build/ \ No newline at end of file diff --git a/backup/ID0001(1).txt b/backup/ID0001(1).txt new file mode 100644 index 0000000..4d952cc --- /dev/null +++ b/backup/ID0001(1).txt @@ -0,0 +1,81 @@ +{ + "SampleNo":"ID0001", + "TestDate":"2023-02-24 11:53", + "TestVaule":[ + { + "标准名称":"0.41" + }, + { + "loss":"0.67" + }, + { + "SiO2":"0.34" + }, + { + "Al2O3":"0.00" + }, + { + "Fe2O3":"0.69" + }, + { + "CaO":"0.24" + }, + { + "MgO":"0.78" + }, + { + "MnO":"0.58" + }, + { + "SO3":"0.62" + }, + { + "P2O5":"0.64" + }, + { + "Cl-":"0.05" + }, + { + "K2O":"0.45" + }, + { + "Na2O":"0.81" + }, + { + "R2O":"0.27" + }, + { + "f-CaO":"0.61" + }, + { + "KH":"0.91" + }, + { + "KH-":"0.95" + }, + { + "SM":"0.42" + }, + { + "IM":"0.27" + }, + { + "LSF":"0.36" + }, + { + "C2S":"0.91" + }, + { + "C3S":"0.04" + }, + { + "C3A":"0.02" + }, + { + "C4AF":"0.53" + }, + { + "SUM":"0.92" + } + ] +} diff --git a/backup/ID0002.txt b/backup/ID0002.txt new file mode 100644 index 0000000..b647506 --- /dev/null +++ b/backup/ID0002.txt @@ -0,0 +1,84 @@ +{ + "SampleNo":"ID0002", + "TestDate":"2023-02-28 10:54", + "TestVaule":[ + { + "检测项目":"0.62" + }, + { + "loss":"0.57" + }, + { + "SiO2":"0.37" + }, + { + "Al2O3":"0.59" + }, + { + "Fe2O3":"0.23" + }, + { + "CaO":"0.41" + }, + { + "MgO":"0.29" + }, + { + "MnO":"0.78" + }, + { + "TiO2":"0.16" + }, + { + "SO3":"0.35" + }, + { + "P2O5":"0.90" + }, + { + "Cl-":"0.42" + }, + { + "K2O":"0.88" + }, + { + "Na2O":"0.06" + }, + { + "R2O":"0.40" + }, + { + "f-CaO":"null" + }, + { + "KH":"null" + }, + { + "KH-":"null" + }, + { + "SM":"null" + }, + { + "IM":"null" + }, + { + "LSF":"null" + }, + { + "C2S":"null" + }, + { + "C3S":"null" + }, + { + "C3A":"null" + }, + { + "C4AF":"null" + }, + { + "SUM":"null" + } + ] +} diff --git a/conf.ini b/conf.ini new file mode 100644 index 0000000..fd5f6d0 --- /dev/null +++ b/conf.ini @@ -0,0 +1,2 @@ +[ctc] +serverUrl=http://127.0.0.1:1234 \ No newline at end of file diff --git a/ctc数据推送.py b/ctc数据推送.py new file mode 100644 index 0000000..bc9ab86 --- /dev/null +++ b/ctc数据推送.py @@ -0,0 +1,77 @@ +import os +import pystray +import threading +from PIL import Image +from pystray import MenuItem +import time +import requests +import json +import shutil +from configparser import ConfigParser +import socket + + +def close(icon, item): + global isWorking + isWorking = False + icon.stop() + + +def check_one_instance(): + try: + global s + s = socket.socket() + host = socket.gethostname() + s.bind((host, 20309)) + return True + except Exception: + print('already has an instance') + return False + + +def main(): + conf = ConfigParser() # 需要实例化一个ConfigParser对象 + conf.read('conf.ini') + global isWorking + isWorking = True + serverUrl = conf['ctc']['serverUrl'] + currentPath = os.getcwd() + backupPath = os.path.join(currentPath, 'backup') + if not os.path.exists(backupPath): + os.mkdir(backupPath) + + menu = (MenuItem('退出', close), ) + image = Image.open("favicon.ico") + title = "ctc数据推送" + icon = pystray.Icon(title, image, "ctc数据推送", menu) + threading.Thread(target=icon.run, daemon=True).start() + + while isWorking: + files = os.listdir(currentPath) + for file in files: + file_path = os.path.join(currentPath, file) + if file_path.endswith('.txt'): + with open(file_path, 'r', encoding="utf-8") as f: + post_data = json.load(f) + for i in post_data['TestVaule']: + for k in i: + if i[k] == 'null': + i[k] = None + try: + requests.post(url=serverUrl, json=post_data) + try: + shutil.move(file_path, backupPath) + except Exception: + os.remove(file_path) + except Exception as e: + err = '服务器错误:{}'.format(e.__str__()[0:80]) + icon.notify(message=err) + time.sleep(3) + + +if __name__ == '__main__': + if check_one_instance(): + main() + + +# pyinstaller -F -w -i favicon.ico ctc数据推送.py diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..f6f458e Binary files /dev/null and b/favicon.ico differ