def main(module): if module == 1: try: i = random.randint(0, len(StoreData.store_list)-1) result = "推荐 {0}!\n".format(StoreData.store_list[i][1].encode('utf-8')) if StoreData.store_list[i][2]: result += "地址为 {0}!".format(StoreData.store_list[i][2].encode('utf-8')) except ValueError: result = "貌似没有可供选择的店呢,新加点店面嗷" if module == 2: StoreData.input_store_name() result = "添加成功" if module == 3: result = "" if len(StoreData.store_list) == 0: result = "貌似没有可供选择的店呢,新加点店面嗷" for i in range(len(StoreData.store_list)): result += '''编号:{0} 店名:{1} 地址:{2}\n''' \ .format(StoreData.all_store[i][0].encode('utf-8'), StoreData.all_store[i][1].encode('utf-8'), StoreData.all_store[i][2].encode('utf-8')) return result
def parse_email(msg, i,email_uidl): """Parse email message and save content & attachments to file :param msg: mail message :param i: ordinal number """ global result_file email_date=get_date(msg) email_address_store=get_from(msg) if email_date!=None: date_store="%s-%s-%s %s:%s"%(email_date[0],email_date[1],email_date[2],email_date[3],email_date[4]) else: date_store="%s-%s-%s %s:%s"%(0,0,0,0,0) StoreData.insert_email_info(email_uidl,email_address_store,date_store) # Parse and save email content and attachments for part in msg.walk(): if not part.is_multipart(): filename = part.get_filename() #content = part.get_payload(decode=True) charset = get_charset(part) if charset == None: #modified by mrxu content = part.get_payload(decode=True) else: content = part.get_payload(decode=True).decode(charset) if filename: # Attachment # Decode filename h = email.Header.Header(filename) dh = email.Header.decode_header(h) filename = dh[0][0] filename_store="mail{0}_attach_{1}".format(i, filename) #date_store="%s-%s-%s %s:%s"%(get_date(msg)[0],get_date(msg)[1],get_date(msg)[2],get_date(msg)[3],get_date(msg)[4]) result_file = os.path.join(result_path, "mail{0}_attach_{1}".format(i, filename)) #print(date_store) print("[-] Found attachment:"+filename), if is_file_exists("mail{0}_attach_{1}".format(i, filename)): print("This File Exists") else: print("New File") try:#输出文件(附件) with open(result_file, "wb") as f: f.write(content) except BaseException as e: print("[-] Write file of email {0} failed: {1}".format(i, e)) md5_store=GetBigFileMD5(result_file) StoreData.insert_attachment(filename_store,md5_store,email_uidl,email_address_store,date_store) else: # Main content modified by mrxu print(" ContentType:"+get_content_type(part)) content_suffix=get_suffix(get_content_type(part)) result_file = os.path.join(result_path, "mail{0}_text".format(i)+content_suffix) '''
def train(userCount, datasetConst, genConst): dataFromFile = {} for userID in range(1, userCount + 1): currentFolderName = os.getcwd() currentFileName = "u" + str(userID) + "s1.txt" fileNameWithPath = os.path.join(currentFolderName, genConst['DatasetFolder'], datasetConst['Folder'], currentFileName) preprocessedTrainData, frameCount = Preprocess.preprocess( fileNameWithPath, datasetConst, genConst) dataFromFile[str(userID)] = [] dataFromFile[str(userID)].append(frameCount) dataFromFile[str(userID)].append(preprocessedTrainData) topNPairIndex = TopNPairIndex.topNPairIndex(dataFromFile, genConst) StoreData.storeData(dataFromFile, topNPairIndex, genConst)
def Train(userCount): # print("IN METHOD TRAIN") maxFrame = 0 for id in range (userCount): locs = [] userName = str(id+1) FileLocation = Constants.Constants.DatasetFolder+"joints_s" # print("Opening", FileLocation) print(FileLocation+str(id+1).zfill(2)+'_e01.txt') fileID = open(FileLocation+str(id+1).zfill(2)+'_e01.txt','r') frameCount = int(fileID.readline().rstrip()) # print("File: ", (id * 2) + 1, " Frame: ", frameCount) data = np.zeros((Constants.Constants.TotalJoints, Constants.Constants.Coordinates , frameCount)) for i in range(frameCount): arr = fileID.readline().rstrip() x = [float(x) for x in arr.split()] for j in range(Constants.Constants.TotalJoints): data[j][0][i] = x[3*j - 2] data[j][1][i] = x[3*j - 1] data[j][2][i] = x[3*j] ankleDistance = CalculateAnkleDistance.CalculateAnkleDistance(data) span = math.floor(len(ankleDistance)/Constants.Constants.SpanDivide) smoothAnkleDistance = smooth(ankleDistance,span) fp = findpeaks(method='peakdetect',lookahead=3) peakDict= fp.fit(smoothAnkleDistance) peak_indices = [] valley_indices = [] index = 0 for i in peakDict['df']['peak']: if(i == True): peak_indices.append(index) index += 1 # index = 0 # for i in peakDict['df']['valley']: # if(i == True): # valley_indices.append(index) # index += 1 # if(len(peak_indices)>= 3 ): # locs = peak_indices # else: # locs = start = peak_indices[0] if(len(peak_indices)<3): fin = len(smoothAnkleDistance) else: fin = peak_indices[2] angleArray = CalculateAngle.CalculateAngle(data[:,:,start:fin]) sz = np.shape(angleArray) maxFrame = max(maxFrame,sz[0]) print(sz[0]) # print("Number of frames", sz[0]) StoreData.StoreData(id+1,id+1,angleArray) fileID.close() fileID = open(Constants.Constants.TrainingSetFolder+'metadata.txt','w') fileID.write(str(userCount)+"\n"+str(maxFrame)+"\n") fileID.close() topNIndex = TopNPairIndex.TopNPairIndex(maxFrame) length = len(topNIndex) fileID = open(Constants.Constants.TrainingSetFolder+'metadata.txt', 'w') fileID.write(str(length)+'\n') for i in range(length): fileID.write(str(int(topNIndex[i]))+' ') fileID.close() # Train(20)
#--------------------Processing________________________ #get data for balance, cleared balance and unique Id objFile = open("Bankfile1.dat", "rb") intUniqueId = pickle.load( objFile ) #Get the unique Id from file: will be incremented by 1 for next transaction. objFile.close() #for cleared balance: get the list of the history of cleared balance calculations objFile = open("ClearedBalanceRecord.dat", "rb") ClearedBalLst = pickle.load(objFile) ClearedBal = ClearedBalLst[-1][0] #this is the most recent cleared balance objFile.close() #for transaction record, get stored data: LstTrans = StoreData.RetrieveTransLst() #Each separate transaction is a list. Balance is the last item in the list. # The last item of the last transaction in LstTrans is the final balance. Balance = LstTrans[-1][-1] print("Welcome to the checking account register\n") print("Ending balance:", Balance) print("Today's balance:", Searches.GetTodaysBalance(LstTrans)) print("Cleared balance:", ClearedBal) print("Last unique ID:", intUniqueId) #Print the last 10 transactions on opening the script: print( "\nLast 10 transactions--------------------------------------------------") LstRecentTrans = LstTrans[-10:] Presentation.PrintRegister(LstRecentTrans)
def pop3(host, port, usr, pwd, use_ssl): """Pop3 handler :param host: host :param port: port :param usr: username :param pwd: password :param use_ssl: True if use SSL else False """ # Connect to mail server try: conn = poplib.POP3_SSL(host, port) if use_ssl else poplib.POP3(host, port) conn.user(usr) conn.pass_(pwd) print("[+] Connect to {0}:{1} successfully".format(host, port)) except BaseException as e: exit_script("Connect to {0}:{1} failed".format(host, port), e) # Get email message number try: msg_num = len(conn.list()[1]) print("[*] {0} emails found in {1}".format(msg_num, usr)) except BaseException as e: exit_script("Can't get email number", e) # Get email content and attachments #for i in range(1, msg_num+1): for current_email_des in conn.uidl()[1]: current_msg_num=current_email_des.split(" ")[0] current_email_uidl=current_email_des.split(" ")[1] #print(current_email_uidl) #print(StoreData.is_email_unread(current_email_uidl)) if StoreData.is_email_unread(current_email_uidl):#如果该邮件未读,则进行下载并解析 print("[*] Unread Eamil ! Downloading email {0}/{1}---uidl:{2}".format(current_msg_num, msg_num,current_email_uidl)) #if i==11: conn.dele(i)#删除邮件 # Retrieve email message lines, and write to buffer try: msg_lines = conn.retr(current_msg_num)[1] buf = cStringIO.StringIO() for line in msg_lines: print >> buf, line buf.seek(0) except BaseException as e: print "[-] Retrieve email {0} failed: {1}".format(current_msg_num, e) continue # Read buffer try: msg = email.message_from_file(buf) except BaseException as e: print "[-] Read buffer of email {0} failed: {1}".format(current_msg_num, e) continue # Parse and save email content/attachments try: #print(" "+get_date(msg)+"|From :"+get_from(msg)+"|To:"+get_to(msg)) parse_email(msg, current_msg_num,current_email_uidl) except BaseException as e: print("[-] Parse email {0} failed: {1}".format(current_msg_num, e)) else: print("[*] Read Email ! Cancel Downloading email {0}/{1}---uidl:{2}".format(current_msg_num, msg_num,current_email_uidl)) # Quit mail server conn.quit()
def parse_email(msg, i, email_uidl): """Parse email message and save content & attachments to file :param msg: mail message :param i: ordinal number """ global result_file email_date = get_date(msg) email_address_store = get_from(msg) if email_date != None: date_store = "%s-%s-%s %s:%s" % (email_date[0], email_date[1], email_date[2], email_date[3], email_date[4]) else: date_store = "%s-%s-%s %s:%s" % (0, 0, 0, 0, 0) StoreData.insert_email_info(email_uidl, email_address_store, date_store) # Parse and save email content and attachments for part in msg.walk(): if not part.is_multipart(): filename = part.get_filename() #content = part.get_payload(decode=True) charset = get_charset(part) if charset == None: #modified by mrxu content = part.get_payload(decode=True) else: content = part.get_payload(decode=True).decode(charset) if filename: # Attachment # Decode filename h = email.Header.Header(filename) dh = email.Header.decode_header(h) filename = dh[0][0] filename_store = "mail{0}_attach_{1}".format(i, filename) #date_store="%s-%s-%s %s:%s"%(get_date(msg)[0],get_date(msg)[1],get_date(msg)[2],get_date(msg)[3],get_date(msg)[4]) result_file = os.path.join( result_path, "mail{0}_attach_{1}".format(i, filename)) #print(date_store) print("[-] Found attachment:" + filename), if is_file_exists("mail{0}_attach_{1}".format(i, filename)): print("This File Exists") else: print("New File") try: #输出文件(附件) with open(result_file, "wb") as f: f.write(content) except BaseException as e: print("[-] Write file of email {0} failed: {1}".format( i, e)) md5_store = GetBigFileMD5(result_file) StoreData.insert_attachment(filename_store, md5_store, email_uidl, email_address_store, date_store) else: # Main content modified by mrxu print(" ContentType:" + get_content_type(part)) content_suffix = get_suffix(get_content_type(part)) result_file = os.path.join( result_path, "mail{0}_text".format(i) + content_suffix) '''
def pop3(host, port, usr, pwd, use_ssl): """Pop3 handler :param host: host :param port: port :param usr: username :param pwd: password :param use_ssl: True if use SSL else False """ # Connect to mail server try: conn = poplib.POP3_SSL(host, port) if use_ssl else poplib.POP3( host, port) conn.user(usr) conn.pass_(pwd) print("[+] Connect to {0}:{1} successfully".format(host, port)) except BaseException as e: exit_script("Connect to {0}:{1} failed".format(host, port), e) # Get email message number try: msg_num = len(conn.list()[1]) print("[*] {0} emails found in {1}".format(msg_num, usr)) except BaseException as e: exit_script("Can't get email number", e) # Get email content and attachments #for i in range(1, msg_num+1): for current_email_des in conn.uidl()[1]: current_msg_num = current_email_des.split(" ")[0] current_email_uidl = current_email_des.split(" ")[1] #print(current_email_uidl) #print(StoreData.is_email_unread(current_email_uidl)) if StoreData.is_email_unread(current_email_uidl): #如果该邮件未读,则进行下载并解析 print("[*] Unread Eamil ! Downloading email {0}/{1}---uidl:{2}". format(current_msg_num, msg_num, current_email_uidl)) #if i==11: conn.dele(i)#删除邮件 # Retrieve email message lines, and write to buffer try: msg_lines = conn.retr(current_msg_num)[1] buf = cStringIO.StringIO() for line in msg_lines: print >> buf, line buf.seek(0) except BaseException as e: print "[-] Retrieve email {0} failed: {1}".format( current_msg_num, e) continue # Read buffer try: msg = email.message_from_file(buf) except BaseException as e: print "[-] Read buffer of email {0} failed: {1}".format( current_msg_num, e) continue # Parse and save email content/attachments try: #print(" "+get_date(msg)+"|From :"+get_from(msg)+"|To:"+get_to(msg)) parse_email(msg, current_msg_num, current_email_uidl) except BaseException as e: print("[-] Parse email {0} failed: {1}".format( current_msg_num, e)) else: print( "[*] Read Email ! Cancel Downloading email {0}/{1}---uidl:{2}". format(current_msg_num, msg_num, current_email_uidl)) # Quit mail server conn.quit()