first commit

This commit is contained in:
caoqianming 2023-03-08 09:10:28 +08:00
commit a176f2a771
6 changed files with 249 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.exe
*.spec
venv/
dist/
build/

81
backup/ID0001(1).txt Normal file
View File

@ -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"
}
]
}

84
backup/ID0002.txt Normal file
View File

@ -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"
}
]
}

2
conf.ini Normal file
View File

@ -0,0 +1,2 @@
[ctc]
serverUrl=http://127.0.0.1:1234

77
ctc数据推送.py Normal file
View File

@ -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

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB