コード例 #1
0
 def parsemsgs(self):
     # parse through all the messages
     for currmess in self.messages:
         # first the dates
         tmpdate = currmess.rawdate[:-5]
         currmess.date = datetime.strptime(tmpdate,self.dfmt)
         currmess.date = tz_adjust_EST_EDT(currmess.date,self.tzdata)
         currmess.dateout = datetime.strftime(currmess.date,self.outfmt)
         currmess.datestamp = time.mktime(datetime.timetuple(currmess.date)) 
         # now the message bodies
         cm = currmess.body 
         maxratio = 0
         maxrat_count = -99999
        # maxrat_line = -99999
         line = cm.lower()
         line = string.rstrip(line,line[string.rfind(line,'sent using sms-to-email'):])
         line = re.sub('(\r)',' ',line)
         line = re.sub('(\n)',' ',line)
         line = re.sub('(--)',' ',line)
         
         if (('ny' in line) or ('by' in line) or ('my' in line) or ('station' in line)):
             currmess.is_gage_msg = True
             # we will test the line, but we need to remove some terms using regex substitutions
             line = re.sub('(ny)','',line)
             line = re.sub('(by)','',line)
             line = re.sub('(my)','',line)
             line = re.sub('(station)','',line)
             line = re.sub('(water)','',line)
             line = re.sub('(level)','',line)
             line = re.sub('(#)','',line)
             # now get rid of the floating point values that should be the stage
             # using regex code from: http://stackoverflow.com/questions/385558/
             # python-and-regex-question-extract-float-double-value
             currmess.station_line = line
             line = re.sub("[+-]? *(?:\d+(?:\.\d*)|\.\d+)(?:[eE][+-]?\d+)?",'', line)
             
             for j,cs in enumerate(self.stations):
                 # get the similarity ratio
                 crat = fuzz.ratio(line,cs)
                 if crat > maxratio:
                     maxratio = crat
                     maxrat_count = j
             currmess.max_prox_ratio = maxratio    
             currmess.closest_station_match = maxrat_count
             
             # rip the float out of the line
             v = re.findall("[+-]? *(?:\d+(?:\.\d*)|\.\d+)(?:[eE][+-]?\d+)?", currmess.station_line)
             try:
                 currmess.gageheight = float(v[0])
             except:
                 continue
コード例 #2
0
def search_debug_scripts(_info, _search_strings):
    for f in search_files:
        readlines = file("/isan/python/scripts/" + f)
        for line in readlines:
            if "#TAGS:" in line:
                process_file_tags(f, line)
                break

    for srch in _search_strings:
        last_best = 30
        best = 0
        #we will grep in our scripts to find out the best match.
        for (s,f) in global_tags: 
            best = fuzz.ratio(s,srch)
            if best >= last_best:
                last_best = best
                best_info.append((best,s,f))


    best_info.reverse()
    once = []

    print "Found following scripts in order of relevance:"
    print "----------------------------------------------"
    for (score, s, f) in best_info:
        if f not in once:
            print " (%d)"%score, f
            once.append(f)
    print "----------------------------------------------"
    print ""
    print ""
    print "Note:"

    print " To display info about script and its functions, do:"
    print "    python"
    print "    import module"
    print "    dir(module)"
    print "    print module.debug_module_reload_delays.func_doc"

    return best_info            
コード例 #3
0
    def parsemsgs(self,site_params):
        # parse through all the messages
        for currmess in self.messages:
            # first the dates
            tmpdate = currmess.rawdate[:-5]
            currmess.date = datetime.strptime(tmpdate,self.dfmt)
            currmess.date = tz_adjust_STD_DST(currmess.date,self.tzdata)
            currmess.dateout = datetime.strftime(currmess.date,self.outfmt)
            currmess.datestamp = time.mktime(datetime.timetuple(currmess.date)) 
            # now the message bodies
            cm = currmess.body 
            # do a quick check that the message body is only a string - not a list
            # a list happens if there is a forwarded message
            if not isinstance(cm,str):
                cm = cm[0].get_payload()
            maxratio = 0
            maxrat_count = -99999
           # maxrat_line = -99999
            line = cm.lower()
            line = string.rstrip(line,line[string.rfind(line,'sent using sms-to-email'):])
            line = re.sub('(\r)',' ',line)
            line = re.sub('(\n)',' ',line)
            line = re.sub('(--)',' ',line)
            
            for citem in site_params.msg_ids:
                if citem.lower() in line:
                    currmess.is_gage_msg = True                    
            if currmess.is_gage_msg == True:
                matched = False # set a flag to see if a match has been found
                # now check for the obvious - that the exact station number is in the line
                for j,cs in enumerate(self.stations):
                    # see if there's an exact match first
                    if cs.lower() in line.lower():
                        maxratio = 100
                        maxrat_count = j
                        matched = True
                        # also strip out the station ID, including possibly a '.' on the end
                        line = re.sub(cs.lower()+'\.','',line)
                        line = re.sub(cs.lower(),'',line)                  
                        currmess.station_line = line                        
                        break
                # if no exact match found, get fuzzy!
                if matched == False:
                    # we will test the line, but we need to remove some terms using regex substitutions
                    for cremitem in site_params.msg_rms:
                        line = re.sub('('+cremitem.lower()+')','',line)
                    # now get rid of the floating point values that should be the stage
                    # using regex code from: http://stackoverflow.com/questions/385558/
                    # python-and-regex-question-extract-float-double-value
                    currmess.station_line = line
                    line = re.sub("[+-]? *(?:\d+(?:\.\d*)|\.\d+)(?:[eE][+-]?\d+)?",'', line)
                    tmp_ints = re.findall("\d+",line)
                    remaining_ints = []
                    for cval in tmp_ints:
                        remaining_ints.append(int(cval))

                    if len(remaining_ints) < 1:
                        maxratio = 0
                        
                    elif ((max(remaining_ints) < self.minstatnum) or 
                        (min(remaining_ints) > self.maxstatnum)):
                        maxratio = 0
                        
                    else:
                        for j,cs in enumerate(self.stations):
                            # get the similarity ratio
                            crat = fuzz.ratio(line,cs)
                            if crat > maxratio:
                                maxratio = crat
                                maxrat_count = j
                currmess.max_prox_ratio = maxratio    
                currmess.closest_station_match = maxrat_count
                
                # rip the float out of the line
                v = re.findall("[+-]? *(?:\d+(?:\.\d*)|\.\d+)(?:[eE][+-]?\d+)?", currmess.station_line)
                try:
                    currmess.gageheight = float(v[0])
                except:
                    continue
コード例 #4
0
    def parsemsgs(self, site_params):
        # parse through all the messages
        for currmess in self.messages:
            # first the dates
            tmpdate = currmess.rawdate[:-5]
            currmess.date = datetime.strptime(tmpdate, self.dfmt)
            currmess.date = tz_adjust_STD_DST(currmess.date, self.tzdata)
            currmess.dateout = datetime.strftime(currmess.date, self.outfmt)
            currmess.datestamp = time.mktime(datetime.timetuple(currmess.date))

            # now the message bodies
            cm = currmess.body
            # do a quick check that the message body is only a string - not a list
            # a list happens if there is a forwarded message
            if not isinstance(cm, str):
                cm = cm[0].get_payload()
            maxratio = 0
            maxrat_count = -99999
            # maxrat_line = -99999
            line = cm.lower()
            line = string.rstrip(
                line, line[string.rfind(line, 'sent using sms-to-email'):])
            line = re.sub('(\r)', ' ', line)
            line = re.sub('(\n)', ' ', line)
            line = re.sub('(--)', ' ', line)

            for citem in site_params.msg_ids:
                if citem.lower() in line:
                    currmess.is_gage_msg = True

            if currmess.robot_status:
                self.process_a_robot_message(currmess)
                continue  ##if we have a robot message, we process it and skip the rest.
                ## we don't want these contributions being logged in the same way.

            if currmess.is_gage_msg == True:
                matched = False  # set a flag to see if a match has been found
                # now check for the obvious - that the exact station number is in the line
                for j, cs in enumerate(self.stations):
                    # see if there's an exact match first
                    if cs.lower() in line.lower():
                        maxratio = 100
                        maxrat_count = j
                        matched = True
                        # also strip out the station ID, including possibly a '.' on the end
                        line = re.sub(cs.lower() + '\.', '', line)
                        line = re.sub(cs.lower(), '', line)
                        currmess.station_line = line
                        break

                # if no exact match found, get fuzzy!
                if matched == False:
                    # we will test the line, but we need to remove some terms using regex substitutions
                    for cremitem in site_params.msg_rms:
                        line = re.sub('(' + cremitem.lower() + ')', '', line)
                    # now get rid of the floating point values that should be the stage
                    # using regex code from: http://stackoverflow.com/questions/385558/
                    # python-and-regex-question-extract-float-double-value
                    currmess.station_line = line
                    line = re.sub(
                        "[+-]? *(?:\d+(?:\.\d*)|\.\d+)(?:[eE][+-]?\d+)?", '',
                        line)
                    ##print line
                    tmp_ints = re.findall("\d+", line)
                    remaining_ints = []
                    for cval in tmp_ints:
                        remaining_ints.append(int(cval))

                    if len(remaining_ints) < 1:
                        maxratio = 0

                    elif ((max(remaining_ints) < self.minstatnum)
                          or (min(remaining_ints) > self.maxstatnum)):
                        maxratio = 0

                    else:
                        for j, cs in enumerate(self.stations):
                            # get the similarity ratio
                            crat = fuzz.ratio(line, cs)
                            if crat > maxratio:
                                maxratio = crat
                                maxrat_count = j
                currmess.max_prox_ratio = maxratio
                currmess.closest_station_match = maxrat_count

                self.extract_gauge_info(currmess)

            else:
                ##this message has no readable gauge, so we log it as a bad message.
                ##print "Bad Message" + str(currmess.header)
                tools.log_bad_contribution(currmess, self)
コード例 #5
0
ファイル: Jarvis2.py プロジェクト: xsoniq/test
            execute_cmd(cmd['cmd'])

    

        except sr.UnknownValueError:
            print("[log] voice not detected")
        except sr.RequestError as e:
            print("log] Unknown Error")


def recognize_cmd(cmd)
    RC = {'cmd':'', percent: 0}
    for c,v in opts['cmds'].items():

        for x in v:
            vrt = fuzz.ratio(cmd, x)
            if vrt > RC['percent']:
                RC['cmd'] = c 
                RC['percent'] = vrt
    return RC 


def execute_cmd(cmd):
    if cmd == 'ctime':
        #playback time
        now = datatime.now()
        speak("Now is" + str(now.hour) + ":" + str(now.minute))
    elif cmd == 'radio':
        #playback radio
        os.system("D:\\\Python\\Enigma - Gravity Of Love.mp3")
    else: