def check_pkg(): oldnum=re.findall('PKGS:(.*)\n', open( configuration.DATA_FILE, 'r').read() )[0] try: p = os.popen("pacman -Qu |wc -l") p = p.read() p = p.rstrip() if ':'+p+' New pkg' not in oldnum : if p!= '0': configuration.backup() open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE+".bak", "r").read().replace( "PKGS:"+oldnum, "PKGS:"+p+" New Pkg" ) ) else: configuration.backup() open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE+".bak", "r").read().replace( "PKGS:"+oldnum, "PKGS:"+"Up-To-Date") ) except Exception,e: print e
def check_tom_celsius(self,response): for a in response: if '<p class="wx-temp">' in a: tempe = re.findall(" ([0-9]+)<sup>°",a)[0] break tempe = str(int((int(tempe)-32)*(float(5)/9))) myfile = open(configuration.DATA_FILE, 'r').read() tempeNOW = re.findall('TOM_TEMP:(.+)°C', myfile)[0] if tempe!=tempeNOW: configuration.backup() open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE+".bak", "r").read().replace( "TOM_TEMP:"+tempeNOW+"°C", "TOM_TEMP:"+tempe+"°C" ) )
def check_tomorrow_weather(self,br): response = br.open("http://www.weather.com/weather/tomorrow/"+configuration.COUNTRY_CODE).readlines() for a in response: if '<p class="wx-phrase' in a: weather = re.findall('">([^<]+)</',a)[0] break old_weather = re.findall('TOMORROW:(.*)\n', open( configuration.DATA_FILE, 'r').read() )[0] if weather != old_weather : configuration.backup() open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE+".bak", "r").read().replace( "TOMORROW:"+old_weather, "TOMORROW:"+weather ) ) return response
def check_temp(self,response): #get the temperature for a in response: if "temperature-fahrenheit" in a: tempe = re.findall('itemprop=\"temperature-fahrenheit\">(\d*)</span>',a)[0] break #convert it to celcius tempe=str(int((int(tempe)-32)*(float(5)/9))) myfile = open(configuration.DATA_FILE, 'r').read() tempeNOW = re.findall('TEMP:(\d*)°C', myfile)[0] if tempe!=tempeNOW: configuration.backup() #replace the temp open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE+".bak", "r").read().replace( "TEMP:"+tempeNOW+"°C", "TEMP:"+tempe+"°C") )
def check_the_email(domain,user,passwd): try: p = imaplib.IMAP4_SSL(domain) p.login(user,passwd) p.select() index, data = p.search(None, 'UnSeen') number_of_msg = 0 sender_array = [] subject_array = [] for num in data[0].split(): k = p.fetch(num, '(BODY.PEEK[])')[1][0][1] k = k.split("\n") for a in k: a = a.rstrip() for internal in k: if internal.startswith("From:"): sender_array.append(internal) if internal.startswith("Subject:"): subject_array.append(internal) number_of_msg = len(subject_array) old_nb_msg = re.findall("Nb Msg: (.*)\n", open( configuration.DATA_FILE,'r').read() )[0] all_emails = open(configuration.DATA_FILE,'r').read().split("Nb Msg: "+old_nb_msg)[1] if int(old_nb_msg) != number_of_msg: nb = "{0}".format(number_of_msg) configuration.backup() if number_of_msg == 0 : string = "- No Emails - \n" else: string = "" i = 0 for a in sender_array: string += a + "\n" string += subject_array[i] + "\n" i+=1 open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE+".bak", "r").read().replace( "Nb Msg: "+old_nb_msg+all_emails , "Nb Msg: " + nb + "\n" +string ) ) except Exception,e: print e
def check_news(): br = FancyURLopener() response = br.open("http://www.archlinux.org/news/").readlines() for a in response: if 'title="View: ' in a: news = re.findall('">([^<]+)</a>',a)[0] break oldnews = re.findall('NEWS:(.*)\n', open( configuration.DATA_FILE, 'r').read() )[0] if oldnews!=news: configuration.backup() open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE+".bak", "r").read().replace( "NEWS:"+oldnews, "NEWS:"+news) )
def check_weather(self,br): response = br.open("http://www.weather.com/weather/tenday/"+configuration.COUNTRY_CODE).readlines() weather = "" for a in response: if 'itemprop=\"weather-phrase\">' in a : weather = re.findall('itemprop=\"weather-phrase\">([^<]+)</span>', a)[0] break #the old weather in the file someweather = re.findall('WEATHER:(\w+ ?\w+)\n', open(configuration.DATA_FILE, 'r').read())[0] if weather != someweather : configuration.backup() #update the data open(configuration.DATA_FILE,"w").write( open(configuration.DATA_FILE + ".bak", "r").read().replace( "WEATHER:"+someweather, "WEATHER:"+weather ) ) return response
def run(self): if( self.test_connection() ): last_chapter = False try: while(last_chapter==False): to_open = "http://www.mangareader.net/" + self.manga_name + "/" + str( int(self.manga_nownumber)+1 ) response = self.br.open( to_open).read() if "is not released yet" in response or "not published yet" in response or response == "": last_chapter = True if self.manga_name + ":" + str(self.manga_nownumber) not in open(configuration.DATA_FILE, "r").read(): Thread(target=self.exec_cmd).start() configuration.backup() open(configuration.DATA_FILE,'w').write(open(configuration.DATA_FILE+".bak", "r").read().replace(self.manga_name+":"+str(self.manga_oldnumber)+":"+ self.manga_olddate, self.manga_name+":"+str(self.manga_nownumber)+":"+self.nowdate)) else: print "not last chapter" self.manga_nownumber = str( int(self.manga_nownumber)+1 ) except Exception,e : print e print "manga run" if "is not released yet. If you liked" in response: if self.manga_name + ":" + str(self.manga_nownumber) not in open(configuration.DATA_FILE, "r").read(): configuration.backup() open(configuration.DATA_FILE,'w').write(open(configuration.DATA_FILE+".bak", "r").read().replace(self.manga_name+":"+str(self.manga_oldnumber)+":"+ self.manga_olddate, self.manga_name+":"+str(self.manga_nownumber)+":"+self.nowdate)) pass