From a176f2a7719da8215d0e46930a7cef906404165a Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 8 Mar 2023 09:10:28 +0800 Subject: [PATCH] first commit --- .gitignore | 5 +++ backup/ID0001(1).txt | 81 +++++++++++++++++++++++++++++++++++++++++ backup/ID0002.txt | 84 +++++++++++++++++++++++++++++++++++++++++++ conf.ini | 2 ++ ctc数据推送.py | 77 +++++++++++++++++++++++++++++++++++++++ favicon.ico | Bin 0 -> 16958 bytes 6 files changed, 249 insertions(+) create mode 100644 .gitignore create mode 100644 backup/ID0001(1).txt create mode 100644 backup/ID0002.txt create mode 100644 conf.ini create mode 100644 ctc数据推送.py create mode 100644 favicon.ico 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 0000000000000000000000000000000000000000..f6f458e70a9f90219b662ed912b52d8cc9fbe3f3 GIT binary patch literal 16958 zcmeI2O^6gn6vu0`;)sNuAREF!xDA|Zqj zBzTY@9vlxj1Q7`mBxEFrNXQ{95`xH1T!MrUToG|4YWw^5OwD%B^mJ8sdUZd#mbb6# z)vJHKS0AscYucCr{zgX)|2Lbh?;5kt7_${ZWNMJ)VH$0*@_*R_We=1+Q1(E!9+*C7 z%yiwXf{R|tR=dA8SSz5F;{CP!OJtkyZnrS~D<)`yW1wBoY3L8=9(4b9-Auv1r9bw< zGuus_)zGKV&(J^6UFdJ&`2WtnU{!7DsNcor0kP8wwka^cu=`II_Vly8SLe{3Buj_*$(*^`)%54G2g7ha_O z>q&r=?}MI1^n7vE|2z9&zCzhl4ous&#$tCLY|Uq@mxUki#sg<3ef=mWp4!$th^+>W|8_8z2IoYZy}*-ueiY*dWQGoQNK)Y^%~E%JwR z+N)R|+iS^><;3c?^Q!e9JdM3itnbE1%71Qg#f44Z{*u$?uVYwsGsO67UrTB?tL%M? z4c;425o51?YlFoVC%--~HvPsM?OX!qAe7b59({1NUv}md&tDaR3&!a=Yg-sd)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