In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-10-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
< len(pickle_load): if pickle_load[i] == 'water': sql = 'SELECT [meterId], [meterDt],[rainAmount] FROM [water].[dbo].[rain] ' \ 'WHERE meterDt=\'' + self.get_time('HOUR') + '\';' status, row_list_rain = self.runsql(sql, 'water', 'rain') if status == 0: row_list = row_list + row_list_rain sql = 'SELECT [meterId],[meterDt],[waterLv] FROM [water].[dbo].[waterLv] ' \ 'WHERE meterDt=\'' + self.get_time('HOUR') + '\';' status, row_list_waterlv = self.runsql(sql, 'water', 'waterLv') if status == 0: row_list = row_list + row_list_waterlv elif pickle_load[i] == 'STDDB_V380': sql = 'SELECT [STCD],[TM],[DRP] FROM [STDDB_V380].[dbo].[ST_PPTN_R] ' \ 'WHERE TM=\'' + self.get_time('HOUR') + '\';' status, row_list_pptn = self.runsql(sql, 'STDDB_V380', 'ST_PPTN_R') if status == 0: row_list = row_list + row_list_pptn sql = 'SELECT [STCD],[TM],[Z] FROM [STDDB_V380].[dbo].[ST_RIVER_R]' \ 'WHERE TM=\'' + self.get_time('HOUR') + '\';' status, row_list_river = self.runsql(sql, 'STDDB_V380', 'ST_RIVER_R') if status == 0: row_list = row_list + row_list_river sql = 'SELECT [STCD],[TM],[RZ] FROM [STDDB_V380].[dbo].[ST_RSVR_R]' \ 'WHERE TM=\'' + self.get_time('HOUR') + '\';' status, row_list_rsvr = self.runsql(sql, 'STDDB_V380', 'ST_RSVR_R') if status == 0: row_list = row_list + row_list_rsvr i = i + 1 except Exception as error: self.write_log('数据库查询总体上报错:\n' + repr(error)) try: info_file = open('.//DATA//info.pik', 'rb') info_list = pickle.load(info_file) except Exception as error: self.write_log('得站点信息列表错误,info.pik已经存在:\n' + repr(error)) try: now_hour = time.localtime().tm_hour info_list[0].append(str(now_hour - 1) + '时 至 ' + str(now_hour) + '时') i = 1 while i < len(info_list): info_list[i][0] m = 0 flag = 0 while m < len(row_list): if str(info_list[i][0][0]) == str(row_list[m][0]): flag = 1 del row_list[m] m = m - 1 m = m + 1 if flag == 1: info_list[i].append(1) else: info_list[i].append(0) i = i + 1 except Exception as error: print(repr(error)) return 1 try: info_list_file = open('.//DATA//info.pik', 'wb') pickle.dump(info_list, info_list_file) return 0 except Exception as error: self.write_log('重新压入数据错误:' + repr(error)) return 1 finally: info_list_file.close() def send_email(self): # 发送邮件 def _format_addr(s): name, addr = parseaddr(s) return formataddr((Header(name, 'utf-8').encode(), addr)) self.write_log('准备发送邮件') file = open('.//DATA//info.pik', 'rb') info_list = pickle.load(file) msg_txt = '' i = 0 while i < len(info_list): n = 0 m = 0 tr = '' while n < len(info_list[i]): if i == 0 or n == 0: if m == 0: tr = tr + '%d' % i + str( info_list[i][n]) + '' m = m + 1 else: tr = tr + '' + str(info_list[i][n]) + '' else: if info_list[i][n] == 0: tr = tr + '无数据' else: tr = tr + '有数据' n = n + 1 tr = tr + '' m = 0 msg_txt = msg_txt + tr i = i + 1 msg_txt = msg_txt + '' try: msg = MIMEText(msg_txt, 'plain', 'utf-8') from_addr = self.email_window.dir_email['user'] password = self.email_window.dir_email['password'] to_addrs = '' for line in self.email_window.list_users: to_addrs = to_addrs + line + ',' stmp_server = self.email_window.dir_email['stmp'] msg['From'] = _format_addr('%s' % (self.email_window.dir_email['user'],from_addr)) msg['To'] = ','.join(to_addrs) msg['Subject'] = Header('%s%s邮件' % (self.email_window.dir_email['name'],self.get_time(), 'utf-8').encode()) server = smtplib.SMTP(stmp_server, 25) server.set_debuglevel(1) server.login(from_addr, password) server.sendmail(from_addr, [to_addrs], msg.as_string()) os.remove('.//DATA//info.pik') server.quit() return 0 except Exception as error: self.write_log('邮件发送失败!\n' + repr(error)) return 1 def auto_start(self): if time.localtime().tm_min != 3: return self.write_log('------------------程序开始------------------') try: path_list = ['.//log', './/DATA'] for dir_path in path_list: dir_path_num = self.path_exists(dir_path) if dir_path_num == 1: pass elif dir_path_num == 0: os.remove(dir_path) os.mkdir(dir_path) else: os.mkdir(dir_path) config_file = './/DATA//DBconfig.pik' config_file_num = self.path_exists(config_file) first_runsql_num = 9 if config_file_num == 0: first_runsql_num = 2 elif config_file_num == 1: os.remove(config_file) first_runsql_num = self.frist_runsql(config_file) else: first_runsql_num = self.frist_runsql(config_file) if first_runsql_num == 2 or first_runsql_num == 4: pass elif first_runsql_num >4: os.remove ('. / / DATA//DBconfig.pik') self.write_log ('DBconfig.pik has a problem. The program terminates.') Return elif first_runsql_num = = 0: self.write_log ('there is no desired database in the database.') Return else: self.write_log ('there is a problem with DBconfig.pik. The program terminates.') Return except Exception as error: self.write_log ('execution error') return try: run_sql_flag = self.run_sql () if run_sql_flag = = 1: return if time.localtime () .tm_hour = = 8: if time.localtime () .tm_min = = 3: I = 0 while I < 4: flag = self.send_email () if flag = = 0: I = 4 break I = I + 1 Time.sleep (300) except Exception as error: self.write_log ('Last period error:\ n' + repr (error)) if _ _ name__ = ='_ main__': if not os.path.exists ('. / / DATA'): os.mkdir ('. / / DATA') app = QApplication (sys.argv) mainwin = mainwindows () sys.exit (app.exec_ ())
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.