地震台站形变数据监控报警软件

import requests
import winsound
import time
import re
import tkinter as tk
import threading
import os
import sys
from PIL import Image, ImageTk


def start_thread():
thread_hi = threading.Thread(target=refresh_data)
# 守护 线程!!!
thread_hi.setDaemon(True)
thread_hi.start()

def alarm():
while True:
winsound.PlaySound('alarm.wav', winsound.SND_FILENAME)

def refresh_data():
global window,chVarStrain,chVarWaterpipe,chVarPendulum
# 伸缩仪界面设计
if chVarStrain.get() == 1:
# print('伸缩仪被选中了!')
label1 = tk.Label(window, text = '伸缩仪北南向:', font = ('微软雅黑', 15))
label1.place(x=20, y=30, anchor='nw')
ns, ew = getStrain()
anno_ns = tk.StringVar()
anno_ns.set(ns)
ns_entry = tk.Entry(window, font = ('微软雅黑', 15), width = 10, textvariable = anno_ns, bg = 'white')
ns_entry.place(x=170, y=30, anchor='nw')
label2 = tk.Label(window, text = '伸缩仪东西向:', font = ('微软雅黑', 15))
label2.place(x=270, y=30, anchor='nw')
anno_ew = tk.StringVar()
anno_ew.set(ew)
ew_entry = tk.Entry(window, font = ('微软雅黑', 15), width = 10, textvariable = anno_ew, bg = 'white')
ew_entry.place(x=430, y=30, anchor='nw')
else:
label1 = tk.Label(window, text = '伸缩仪北南向:', font = ('微软雅黑', 15))
label1.place(x=20, y=30, anchor='nw')
ns='未监控'
ew='未监控'
anno_ns = tk.StringVar()
anno_ns.set(ns)
ns_entry = tk.Entry(window, font = ('微软雅黑', 15), width = 10, textvariable = anno_ns,bg = 'red')
ns_entry.place(x=170, y=30, anchor='nw')
label2 = tk.Label(window, text = '伸缩仪东西向:', font = ('微软雅黑', 15))
label2.place(x=270, y=30, anchor='nw')
anno_ew = tk.StringVar()
anno_ew.set(ew)
ew_entry = tk.Entry(window, font = ('微软雅黑', 15), width = 10, textvariable = anno_ew, bg = 'red')
ew_entry.place(x=430, y=30, anchor='nw')

#水管仪界面设计
if chVarWaterpipe.get() == 1:
label3 = tk.Label(window, text='水管仪北端:', font=('微软雅黑', 15))
label3.place(x=20, y=90, anchor='nw')
n,s,e,w = getWaterpipe()
anno_ns = tk.StringVar()
anno_ns.set(n)
ns_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ns, bg = 'white')
ns_entry.place(x=170, y=90, anchor='nw')
label4 = tk.Label(window, text='水管仪东端:', font=('微软雅黑', 15))
label4.place(x=270, y=90, anchor='nw')
anno_ew = tk.StringVar()
anno_ew.set(s)
ew_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ew, bg = 'white')
ew_entry.place(x=430, y=90, anchor='nw')
else:
label3 = tk.Label(window, text='水管仪北端:', font=('微软雅黑', 15))
label3.place(x=20, y=90, anchor='nw')
n='未监控'
s='未监控'
e='未监控'
w='未监控'
anno_ns = tk.StringVar()
anno_ns.set(n)
ns_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ns, bg = 'red')
ns_entry.place(x=170, y=90, anchor='nw')
label4 = tk.Label(window, text='水管仪东端:', font=('微软雅黑', 15))
label4.place(x=270, y=90, anchor='nw')
anno_ew = tk.StringVar()
anno_ew.set(s)
ew_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ew, bg = 'red')
ew_entry.place(x=430, y=90, anchor='nw')


#垂直摆界面设计
if chVarPendulum.get() == 1:
label5 = tk.Label(window, text='垂直摆北南:', font=('微软雅黑', 15))
label5.place(x=20, y=150, anchor='nw')
n,s = getPendulum()
anno_ns = tk.StringVar()
anno_ns.set(n)
ns_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ns, bg = 'white')
ns_entry.place(x=170, y=150, anchor='nw')
label6 = tk.Label(window, text='垂直摆东西端:', font=('微软雅黑', 15))
label6.place(x=270, y=150, anchor='nw')
anno_ew = tk.StringVar()
anno_ew.set(s)
ew_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ew, bg = 'white')
ew_entry.place(x=430, y=150, anchor='nw')
else:
label5 = tk.Label(window, text='垂直摆北南:', font=('微软雅黑', 15))
label5.place(x=20, y=150, anchor='nw')
n = '未监控'
s = '未监控'
anno_ns = tk.StringVar()
anno_ns.set(n)
ns_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ns, bg = 'red')
ns_entry.place(x=170, y=150, anchor='nw')
label6 = tk.Label(window, text='垂直摆东西端:', font=('微软雅黑', 15))
label6.place(x=270, y=150, anchor='nw')
anno_ew = tk.StringVar()
anno_ew.set(s)
ew_entry = tk.Entry(window, font=('微软雅黑', 15), width=10, textvariable=anno_ew, bg = 'red')
ew_entry.place(x=430, y=150, anchor='nw')


load = Image.open('logo2.png') # 插入图片
render = ImageTk.PhotoImage(load)
img = tk.Label(window, image=render)
img.image = render
img.place(x=360, y=200, anchor = 'nw')

window.after(60000,func = refresh_data)

def getWaterpipe():
tilt_url = 'http://10.22.114.31/realtime.cgi'
try:
response = requests.get(tilt_url)
except:
alarm()
res = re.compile(r'</font><b><font color="#3333FF" size="6">(.*?)mV</font>')
ns = re.findall(res, response.text) # 返回真正的视频文件的下载地址
res = re.compile(r'<b>(.*?)mV</b>')
x = re.findall(res, response.text) # 返回真正的视频文件的下载地址
ns.append(x[0])
if abs(eval(ns[0])) >= 2000 or abs(eval(ns[1])) >= 2000 or abs(eval(ns[2])) >= 2000 or abs(eval(ns[3])) >= 2000:
alarm()
# print('水管仪:',(ns[0],ns[1],ns[2],ns[3]))
return(ns[0],ns[1],ns[2],ns[3])

def getPendulum():

tilt_url = 'http://10.22.114.34/cgi-bin/realtime.cgi'
try:
response = requests.get(tilt_url)
except:
alarm()
res = re.compile(r'>(.*?)mV<')
ns = re.findall(res, response.text) # 返回真正的视频文件的下载地址
ns[0] = ns[0].split('>')[-1]
ns[1] = ns[1].split('>')[-1]
if abs(eval(ns[0])) >= 2500 or abs(eval(ns[1])) >= 2500:
alarm()
# print('垂直摆:',(ns[0],ns[1]))
return(ns[0],ns[1])


def getStrain():
while True:
tilt_url = 'http://10.22.114.32/realtime.cgi'
try:
response = requests.get(tilt_url)
except:
alarm()
res = re.compile(r'>(.*?)mV<')
strain_ns = re.findall(res, response.text) # 返回真正的视频文件的下载地址
strain_ns[0] = strain_ns[0].split('>')[-1]
strain_ns[1] = strain_ns[1].split('>')[-1]
if abs(eval(strain_ns[0])) >= 2000 or abs(eval(strain_ns[1])) >= 2000:
alarm()
# print('伸缩仪:',(strain_ns[0],strain_ns[1]))
return(strain_ns[0],strain_ns[1])



def main():
global window, chVarWaterpipe, chVarStrain, chVarPendulum
window = tk.Tk()
window.title('形变数据监控软件V2.2 Copyright © 吉林省长白山天池火山监测站 2020-05-25')
window.geometry('600x400')
lab = tk.Label(window, font=('微软雅黑', 15), width=10,text='报警测项:')
lab.place(x=20,y=210,anchor='nw')
frm = tk.Frame(window)
chVarWaterpipe = tk.IntVar()
ck1 = tk.Checkbutton(frm,text='水管仪',font=('微软雅黑', 15), width=10,variable = chVarWaterpipe)
chVarStrain = tk.IntVar()
ck2 = tk.Checkbutton(frm,text='伸缩仪',font=('微软雅黑', 15), width=10,variable = chVarStrain)
chVarPendulum = tk.IntVar()
ck3 = tk.Checkbutton(frm,text='垂直摆',font=('微软雅黑', 15), width=10,variable = chVarPendulum)
ck1.grid(row = 0, column =1)
ck2.grid(row = 1, column =1)
ck3.grid(row = 2, column =1)
frm.place(x=200,y=210,anchor='nw')
# 定义开始监测按钮
sure = tk.Button(window, text = '开始监控', font=('微软雅黑', 15),width = 10, command = start_thread)
sure.place(x = 20, y = 270, anchor = 'nw')
calculate = tk.Button(window, text='结束运行', font=('微软雅黑', 15),width = 10, command= window.quit)
calculate.place(x=20, y=330, anchor='nw')
window.mainloop()

main()
posted @ 2020-05-24 20:11  Iceberg_710815  阅读(307)  评论(0编辑  收藏  举报