def _parseHtml (self, html): """Parse HTML""" ret = [] soup = BeautifulSoup (html) for div in soup.findAll ("div", {"class": "giaeffettuate"}) + soup.findAll ("div", {"class": "corpocentrale"}): station = div.find ("h2") station = str (station.contents[0]) # Now get the time prog = None real = None tag = None for p in div.findAll ("p"): t = str (p.contents[0]) time = p.find ("strong") if len (time.contents) > 0: time = str (time.contents[0]) else: time = "00:00" if re.search ("(?i)programmat(a|o)", t): prog = time.rstrip().lstrip() elif re.search ("(?i)effettiv(a|o)", t): real = time.rstrip().lstrip() tag = "eff" elif re.search ("(?i)previst(a|o)", t): real = time.rstrip().lstrip() tag = "est" assert (prog is not None and real is not None and tag is not None) print station print prog print real print tag e = (station, prog, real, self.timediff (prog, real), tag) ret.append (e) return ret
def main(): opfile=open('xev_output') buttonpress=re.compile('ButtonPress.*') buttonRelease=re.compile('ButtonRelease.*') noButtonPress=re.compile('(?!.*ButtonPress).*event.*') timestack=list() timeflag=0 doubleflag=0 windowstack=list() lineStack=list() for line in opfile: if(timeflag==1): vals=line.split() time=vals[5] timestack.append(int(time.rstrip(','))) timeflag=0 if(timeflag==2): lineStack.append(line) vals=line.split() time=vals[5] timestack.append(int(time.rstrip(','))) doubleflag=doubleflag+1 if(doubleflag==2): time1=timestack.pop() time2=timestack.pop() time3=timestack.pop() time4=timestack.pop() if(time4-time2<500): temp=vals[7].split(',') print temp print temp[0].split('(')[1],temp[1].strip(')') enterData('DoubleClick',windowstack.pop().strip(','),temp[0].split('(')[1],temp[1].strip(')')) else: window=windowstack.pop() temp=vals[7].split(',') enterData('SingleClick',window.strip(','),temp[0].split('(')[1],temp[1].strip(')')) enterData('singleClick',window.strip(','),temp[0].split('(')[1],temp[1].strip(')')) print time1,time2,time3,time4 doubleflag=0 timeflag=0 val1=buttonpress.match(line) if val1!=None: timeflag=1 val2=buttonRelease.match(line) if val2!=None: window=line.split()[7] windowstack.append(window) timeflag=2 val3=noButtonPress.match(line) if(val3!=None and len(timestack)==2): temp=lineStack.pop().split()[7].split(',') timestack.pop() timestack.pop() enterData('SingleClick',windowstack.pop().strip(','),temp[0].split('(')[1],temp[1].strip(')')) doubleflag=0
def read_best_times(): best_times = [] with open("best times.txt", "r") as open_file: for time in open_file: if time.rstrip() == "None": best_times.append(None) else: best_times.append(float(time.rstrip())) return best_times
def getData(self): """ Returns a dictionary with all weather variables for each initHour that is the database for the current week""" print("a ver che...") from forecastiopy import ForecastIO # TODO: A method that will get the weather variables for the activity # initHour when the time comes. DONE Cordoba = [-31.4173,-64.1833] # TODO: Avoid this hardcoded data language= 'es' with open("forecast.txt", "r") as file: forecastAPI= file.readlines().pop().rstrip('\n') _,timeRange = ActivityRegister( self.database,self.activity,self.initHour).periodReport('semanal') weatherData = dict() timeRange.sort() for time in timeRange: weatherData[time] = dict() weatherData[time]['participants'] = ActivityRegister( self.database,self.activity,unicode(time)).howMuch() fio = ForecastIO.ForecastIO(forecastAPI, latitude=Cordoba[0], longitude=Cordoba[1],lang=language) fio.time_url=time.rstrip('0').rstrip('.') #needs to be done couse #the api doesn't support floating point time forecast = json.loads(fio.http_get(fio.get_url())) for key in forecast['currently'].keys(): weatherData[time][key]=forecast['currently'][key] # print(time,key,datos,weatherData[time][key]) #'summary','apparentTemperature','precipIntensity', #'humidity','pressure','precipProbability','windSpeed', #'Among others variables' setattr(self, 'data',weatherData)
def getData(self): """ Returns a dictionary with all weather variables for each initHour that is the database for the current week""" print("a ver che...") from forecastiopy import ForecastIO # TODO: A method that will get the weather variables for the activity # initHour when the time comes. DONE Cordoba = [-31.4173, -64.1833] # TODO: Avoid this hardcoded data language = 'es' with open("forecast.txt", "r") as file: forecastAPI = file.readlines().pop().rstrip('\n') _, timeRange = ActivityRegister(self.database, self.activity, self.initHour).periodReport('semanal') weatherData = dict() timeRange.sort() for time in timeRange: weatherData[time] = dict() weatherData[time]['participants'] = ActivityRegister( self.database, self.activity, unicode(time)).howMuch() fio = ForecastIO.ForecastIO(forecastAPI, latitude=Cordoba[0], longitude=Cordoba[1], lang=language) fio.time_url = time.rstrip('0').rstrip( '.') #needs to be done couse #the api doesn't support floating point time forecast = json.loads(fio.http_get(fio.get_url())) for key in forecast['currently'].keys(): weatherData[time][key] = forecast['currently'][key] # print(time,key,datos,weatherData[time][key]) #'summary','apparentTemperature','precipIntensity', #'humidity','pressure','precipProbability','windSpeed', #'Among others variables' setattr(self, 'data', weatherData)
def seconds_to_time_string(total_seconds, *, int_seconds=False, format=1): days = int(total_seconds // 86400) rest = total_seconds % 86400 hours = int(rest // 3600) rest = rest % 3600 minutes = int(rest // 60) seconds = rest % 60 if days == hours == minutes == 0 and not int_seconds: seconds = round(seconds, 1) if seconds == 0: seconds = 1 else: seconds = int(seconds) # noinspection PyShadowingNames time = "" if format == 1: if days: time += f"{plural(days):day} " if hours: time += f"{plural(hours):hour} " if minutes: time += f"{plural(minutes):minute} " if seconds or not time: time += f"{plural(seconds):second}" elif format == 2: if days: time += f"{plural(days): day}, " if days or hours: time += f"{hours: >2}:" time += f"{minutes:0>2}:" else: time += f"{minutes: >2}:" time += f"{seconds:0>2}" else: if days: time += f"{days}d " if hours: time += f"{hours}h " if minutes: time += f"{minutes}m " if seconds or not time: time += f"{seconds}s" return time.rstrip()
def format_time(self, time): time = time.rstrip() # First check to ensure the time is labeled with AM or PM, Three cases: # 1. Last character in time is "M" (Time is correctly labeled with AM or PM) # 2. Last character in time is "A" or "P" (Add in the "M") # 3. Last Last character in time is none of the above (Add "AM" or "PM" based on time value) am_pm = time[-1:].upper() if am_pm == "A" or am_pm == "P": time = time + "M" am_pm = "M" if am_pm != "M": time = self.add_am_pm(time) times = time[:-2].split(':') if len(times) > 1: # Time is already in HH:MMam/pm format return time[:-2] + ":00 " + time[-2:].upper() else: return time[:-2] + ":00:00 " + time[-2:].upper()
def main(): opfile = open('xev_output') buttonpress = re.compile('ButtonPress.*') buttonRelease = re.compile('ButtonRelease.*') noButtonPress = re.compile('(?!.*ButtonPress).*event.*') timestack = list() timeflag = 0 doubleflag = 0 windowstack = list() lineStack = list() for line in opfile: if (timeflag == 1): vals = line.split() time = vals[5] timestack.append(int(time.rstrip(','))) timeflag = 0 if (timeflag == 2): lineStack.append(line) vals = line.split() time = vals[5] timestack.append(int(time.rstrip(','))) doubleflag = doubleflag + 1 if (doubleflag == 2): time1 = timestack.pop() time2 = timestack.pop() time3 = timestack.pop() time4 = timestack.pop() if (time4 - time2 < 500): temp = vals[7].split(',') print temp print temp[0].split('(')[1], temp[1].strip(')') enterData('DoubleClick', windowstack.pop().strip(','), temp[0].split('(')[1], temp[1].strip(')')) else: window = windowstack.pop() temp = vals[7].split(',') enterData('SingleClick', window.strip(','), temp[0].split('(')[1], temp[1].strip(')')) enterData('singleClick', window.strip(','), temp[0].split('(')[1], temp[1].strip(')')) print time1, time2, time3, time4 doubleflag = 0 timeflag = 0 val1 = buttonpress.match(line) if val1 != None: timeflag = 1 val2 = buttonRelease.match(line) if val2 != None: window = line.split()[7] windowstack.append(window) timeflag = 2 val3 = noButtonPress.match(line) if (val3 != None and len(timestack) == 2): temp = lineStack.pop().split()[7].split(',') timestack.pop() timestack.pop() enterData('SingleClick', windowstack.pop().strip(','), temp[0].split('(')[1], temp[1].strip(')')) doubleflag = 0
'senderid':senderId } return requests.post(reqUrl, req_params) # ssh log file Log_File= "/var/log/secure" #startting log scanner with open (Log_File,'r') as f: while 1: where = f.tell() line = f.readline() f_line = str(line) if "Acc" in f_line: print(f_line) user = re.search(r"for(.*)from",f_line).group(1) time = re.findall("[0-9]{,2}:[0-9]{,2}:[0-9]{,2}",f_line) time=str(time) time = time.rstrip("]").lstrip("[") ip = re.findall("[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}",f_line) ip = str(ip) ip = ip.rstrip("]").lstrip("[") message = "New connection to account"+ user +"from ip "+ ip + " at "+ time +" IST" print(message) response = sendPostRequest(URL, 'apiKey' , 'secretKey', 'stage', 'your_mobile_number', 'active-sender-id', message) print(response.text) if not line: print("waiting for new line. position is at".format(where)) time.sleep(2) f.seek(where)
def getLastSync(self): f = open(homepath + "lastSync","r") time = f.read() f.close() return time.rstrip()