def parse_sql(line): val = line_parser.parse(line) if val: valeurs = {} valeurs["categorie"] = val["cat_id"] valeurs["date"] = val["post_dt"] valeurs["slug"] = val["post_url"] valeurs["title"] = val["post_title"] valeurs["content"] = val["post_content"] valeurs["excerpt"] = val["post_excerpt"] valeurs["status"] = 1 # Notre parser ne garde que les billets actifs valeurs["blog_id"] = val["blog_id"] return valeurs
cursor.execute("TRUNCATE TABLE ore") sheet = file_xls.sheet_by_index(0) #get sheet and pass it to read line if(end_check==0): end_check=start_check if(start_check==0): start_check=3 end_check=sheet.nrows index_line=start_check-1 while index_line<end_check: line=line_reader.read_line(sheet,index_line) error_check=prev_error prev_error=line_parser.parse(line,index_line,prev_error) #if "OK" data is consistent if error_check==prev_error: prev_error=db_writer.db_write_line(cursor,line,index_line,prev_error) #pass the line and its number #elif error_check=="Ignore": # print "Line ",index_line+2," has been ignored " # elif (prev_error<3): # print "\n\n --------------------------------- \n " # print "Data missing on line :", # print error_check+1," Sheet :",sheet.name # prev_error=prev_error+1 #else: # prev_error=prev_error+1 index_line+=1 cursor.execute("TRUNCATE TABLE ore") print "\n Only first 5 errors are displayed (if any) !!! "
################################################ # # for each sheet ot the file get all line # ################################################ index_line=2 #get sheet and pass it to read line sheet = file_xls.sheet_by_index(0) while index_line<sheet.nrows: print index_line," -------------->" line=line_reader.read_line(sheet,index_line) error_check=line_parser.parse(line,index_line) #if "OK" data is consistent if error_check=="Ok": print "Line ",index_line+2," is candidate to be inserted into DB" db_writer.db_write_line(cursor,line,index_line) #pass the line and its number elif error_check=="Ignore": print "Line ",index_line+2," has been ignored >>> " else: print "Data missing on line :", print error_check+1," Sheet :",sheet.name print "Please correct XLS file" #index_sheet=file_xls.nsheets #break index_line+=1 #test read first line in xls file -> uncomment next line to test #print "Line 0 : ",reader.read_line(xls_file,0,0)
stream_rep.start() while True: # Check if input exists, wait up to timeout_s seconds rlist, wlist, xlist = select.select([sys.stdin], [], [], config.INPUT_TIMEOUT_S) if len(rlist) == 0: sys.exit('Error: Input Timeout: ' + str(datetime.datetime.now())) # Get and parse input line = sys.stdin.readline() start_time = datetime.datetime.now() while len(line) < 1: if (datetime.datetime.now() - start_time).seconds > config.INPUT_TIMEOUT_S: client.send('Input Timeout ' + str(datetime.datetime.now())) sys.exit('Error: Input Timeout ' + str(datetime.datetime.now())) line = sys.stdin.readline() ret = line_parser.parse(line) protocol = ret[0] # Skip bad lines if protocol == '': continue packet = ret[1] # Skip local -> local connections # print 'Protocol: ', protocol # if re.match(re_local_ip, packet.ip_source) and re.match(re_local_ip, packet.ip_dest): if config.localIP(packet.ip_source) and config.localIP(packet.ip_dest): continue # if (not re.match(re_local_ip, packet.ip_source)) and (not re.match(re_local_ip, packet.ip_dest)): if (not config.localIP(packet.ip_source)) and (not config.localIP(packet.ip_dest)):