def listening(self, queue): assert isinstance(queue, Queue.Queue) inputs = [self.server] while inputs: rs, ws, es = select.select(inputs, [], [], 5) for r in rs: if r is self.server: clientsock, clientaddr = r.accept() inputs.append(clientsock) else: data = r.recv(2048) #if not data: #inputs.remove(r) if data: print data, 'Incomming from ', clientaddr queue.put(data) data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') #data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.dat')) data_operator.write_data(data) else: print 'no data comming, closing' inputs.remove(r)
def handle_read(self): data =self.recv(1024) if data : print data GPRS_handler.current_data = data GPRS_handler.current_flag = time.strftime('%Y-%m-%d:%H:%M%S') data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator.write_data(data)
def handle_read(self): data = self.recv(1024) if data: print data GPRS_handler.current_data = data GPRS_handler.current_flag = time.strftime('%Y-%m-%d:%H:%M%S') data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.txt')) data_operator.write_data(data)
def read_text(self): data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.dat')) self.ip_var.set(data_config['ip']) self.port_var.set(data_config['port']) self.directory_var.set(data_config['data_dir']) data = data_operator.read_data() #print data self.receiver_data.insert(END,''.join(data)) #data_operator.write_data(data) self.pre_date = datetime.now()
def recv(self,queue): while True: try : data = self.server.recv(0xfff) print time.strftime('%Y-%m-%d %h:%M:%s'),data,'Incomming from '#,clientaddr queue.put(data) data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator.write_data(data) except Exception,e: print e
def read_text(self): data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.dat')) self.ip_var.set(data_config['ip']) self.port_var.set(data_config['port']) self.directory_var.set(data_config['data_dir']) data = data_operator.read_data() #print data self.receiver_data.insert(END, ''.join(data)) #data_operator.write_data(data) self.pre_date = datetime.now()
def recv(self, queue): while True: try: data = self.server.recv(0xfff) print time.strftime( '%Y-%m-%d %h:%M:%s'), data, 'Incomming from ' #,clientaddr queue.put(data) data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y-%m-%d') data_operator = GPRS_data_operator( os.path.join(data_config['data_dir'], data_time + '.dat')) data_operator.write_data(data) except Exception, e: print e
def send_mail(sub,content,to_str=None,att='window.py'): if to_str is None : to_str = GPRS_data_operator.read_email_receiver() me="snowobservation"+"<"+mail_user+"@"+mail_postfix+">" #msg = MIMEText(content,_subtype='plain',_charset='utf-8') msg = MIMEMultipart() msg['Subject'] = Header(sub,'utf-8').encode() msg['From'] = me msg['To'] = ";".join(to_str) if att is not None : part = MIMEBase('application','octet-stream') part.set_payload(open(att,'rb').read()) Encoders.encode_base64(part) part.add_header('Content-Disposition','attachment; filename="%s"' %os.path.basename(att)) part.add_header('Content-ID', '<0>') part.add_header('X-Attachment-Id', '0') msg.attach(part) #msg['To'] = to_str try: server = smtplib.SMTP() #server.set_debuglevel(1) server.connect(mail_host) server.login(mail_user,mail_pass) server.sendmail(me, to_str, msg.as_string()) server.close() return True except Exception, e: print str(e) return False
def send_mail(self): send_date = self.pre_date.strftime('%Y%m%d') temp_config = GPRS_data_operator.read_config() try : GPRS_SendEmail(sub='Data of '+send_date, content='There is auto-sender of GPRS_receiver', att=os.path.join(temp_config['data_dir'],send_date+'.dat')) print send_mail,': send email ok!' except Exception as msg: print 'send email faild,',msg
def send_mail(self): send_date = self.pre_date.strftime('%Y%m%d') temp_config = GPRS_data_operator.read_config() try: GPRS_SendEmail(sub='Data of ' + send_date, content='There is auto-sender of GPRS_receiver', att=os.path.join(temp_config['data_dir'], send_date + '.dat')) print send_mail, ': send email ok!' except Exception as msg: print 'send email faild,', msg
def listening(self,queue): assert isinstance(queue,Queue.Queue) #inputs = [self.server] while True: #clientsock,clientaddr = self.server.accept() #rs,ws,es = select.select(inputs,[],[],5) #for r in rs: # if r is self.server: # clientsock,clientaddr = r.accept() # inputs.append(clientsock) # else : # data = r.recv(0xfff) # #if not data: # #inputs.remove(r) # if data : # print data,'Incomming from ',clientaddr # queue.put(data) # data_config = GPRS_data_operator.read_config() # data_time = time.strftime('%Y%m%d') # data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) # data_operator.write_data(data) conn,addr = self.server.accept() print addr,'is connected!' try : data = conn.recv(2048) if len(data)>0: print data,'Incomming from ',addr data_config = GPRS_data_operator.read_config() data_time = time.strftime('%Y%m%d') data_operator = GPRS_data_operator(os.path.join(data_config['data_dir'],data_time+'.txt')) data_operator.write_data(data) queue.put(data) else : conn.shutdown(socket.SHUT_RDWR) conn.close() except Exception as msg: conn.shutdown(socket.SHUT_RDWR) conn.close() print msg
def btn_listbox_add(self): new_email = self.email_var.get() self.receiver_list.append(new_email) GPRS_data_operator.alter_email_receiver(self.receiver_list) self.listbox.insert(END,new_email)
def btn_listbox_add(self): new_email = self.email_var.get() self.receiver_list.append(new_email) GPRS_data_operator.alter_email_receiver(self.receiver_list) self.listbox.insert(END, new_email)
def btn_listbox_del(self): index_tuple = self.listbox.curselection() print index_tuple[0] del self.receiver_list[index_tuple[0]] GPRS_data_operator.alter_email_receiver(self.receiver_list) self.listbox.delete(index_tuple[0])
def btn_alter_port(self): GPRS_data_operator.alter_port(self.port_var.get())
def btn_alter_ip(self): GPRS_data_operator.alter_ip(self.ip_var.get())
def btn_alter_directory(self): GPRS_data_operator.alter_directory(self.directory_var.get())
def read_receiver_list(self): self.receiver_list = GPRS_data_operator.read_email_receiver() for item in self.receiver_list : self.listbox.insert(END,item)
def read_receiver_list(self): self.receiver_list = GPRS_data_operator.read_email_receiver() for item in self.receiver_list: self.listbox.insert(END, item)
from email import Encoders from email.header import Header from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from GPRS_data_operator import GPRS_data_operator import os #mailto_str = ['zlx<*****@*****.**', # '*****@*****.**', # '*****@*****.**', # '*****@*****.**'] #mail_host="smtp.tongji.edu.cn" #设置服务器 #mail_user="******" #用户名 #mail_pass="******" #口令 #mail_postfix="tongji.edu.cn" #发件箱的后缀 email_sender = GPRS_data_operator.read_email_sender() mail_host = email_sender['host'] mail_user = email_sender['user'] mail_pass = email_sender['pass'] mail_postfix = email_sender['postfix'] def send_mail(sub,content,to_str=None,att='window.py'): if to_str is None : to_str = GPRS_data_operator.read_email_receiver() me="snowobservation"+"<"+mail_user+"@"+mail_postfix+">" #msg = MIMEText(content,_subtype='plain',_charset='utf-8') msg = MIMEMultipart() msg['Subject'] = Header(sub,'utf-8').encode() msg['From'] = me msg['To'] = ";".join(to_str)