Example #1
0
def snext(self):
	if len(self.msg) == 5 and Cache.dataCache and Cache.dataIndex <= len(Cache.dataCache):
		title = "{0}".format(Cache.dataCache[Cache.dataIndex].a)
		title = syscmd.delHtml(title)
		string = "{0}: http://stackoverflow.com{1}".format(title.strip(), Cache.dataCache[Cache.dataIndex].a.get('href').strip())
		self.send_chan(string)
		Cache.dataIndex += 1
		return(True)
Example #2
0
def gnext(self):
	if len(self.msg) == 5 and Cache.dataCache and Cache.dataIndex <= len(Cache.dataCache):
		title = "{0}".format(Cache.dataCache[Cache.dataIndex].a)
		title = syscmd.delHtml(title)
		string = "{0}: {1}".format(title, Cache.dataCache[Cache.dataIndex].a.get('href'))
		self.send_chan(string)
		Cache.dataIndex += 1
		return(True)
Example #3
0
def gnext(self):
    if len(self.msg) == 5 and Cache.dataCache and Cache.dataIndex <= len(
            Cache.dataCache):
        title = "{0}".format(Cache.dataCache[Cache.dataIndex].a)
        title = syscmd.delHtml(title)
        string = "{0}: {1}".format(
            title, Cache.dataCache[Cache.dataIndex].a.get('href'))
        self.send_chan(string)
        Cache.dataIndex += 1
        return (True)
Example #4
0
def snext(self):
    if len(self.msg) == 5 and Cache.dataCache and Cache.dataIndex <= len(
            Cache.dataCache):
        title = "{0}".format(Cache.dataCache[Cache.dataIndex].a)
        title = syscmd.delHtml(title)
        string = "{0}: http://stackoverflow.com{1}".format(
            title.strip(),
            Cache.dataCache[Cache.dataIndex].a.get('href').strip())
        self.send_chan(string)
        Cache.dataIndex += 1
        return (True)
Example #5
0
def googleSearch(self):
    try:
        Cache.dataCache = []
        Cache.dataIndex = 0
        parameters = ""
        length = len(self.msg)

        for x in range(4, length):
            parameters += "{0} ".format(self.msg[x])
        parameters_url = urllib.parse.quote(parameters.strip())

        url = "https://www.google.fi/search?q={0}".format(parameters_url)
        html = syscmd.getHtml(self, url, True)
    except:
        self.errormsg = "[NOTICE]-[google] googleSearch()(1) Something went wrong getting the html"
        sysErrorLog.log(self)

        if self.config["debug"]:
            print("{0}{1}{2}".format(self.color("blue"), self.errormsg,
                                     self.color("end")))
    try:
        try:
            soup = BeautifulSoup(html, "lxml")
        except:
            soup = BeautifulSoup(html, "html5lib")
        Cache.dataCache = soup.findAll("h3", {"class": "r"})
        if len(Cache.dataCache) > 0:
            title = "{0}".format(Cache.dataCache[Cache.dataIndex].a)
            title = syscmd.delHtml(title)
            string = "{0}: {1}".format(
                title, Cache.dataCache[Cache.dataIndex].a.get('href'))
            self.send_chan(string)
            Cache.dataIndex += 1
        else:
            self.send_chan("No results for: {0}".format(parameters))
    except Exception as e:
        self.errormsg = "[ERROR]-[google] googleSearch()(2) stating: {0}".format(
            e)
        sysErrorLog.log(self)  ## LOG the error
        if self.config["debug"]:
            print("{0}{1}{2}".format(self.color("red"), self.errormsg,
                                     self.color("end")))
Example #6
0
def googleSearch(self):
	try:
		Cache.dataCache = []
		Cache.dataIndex = 0
		parameters = ""
		length = len(self.msg)
		
		for x in range (4, length):
			parameters += "{0} ".format(self.msg[x])
		parameters_url = urllib.parse.quote(parameters.strip())
		
		url = "https://www.google.fi/search?q={0}".format(parameters_url)
		html = syscmd.getHtml(self, url, True )
	except:
		self.errormsg = "[NOTICE]-[google] googleSearch()(1) Something went wrong getting the html"
		sysErrorLog.log( self )
		
		if self.config["debug"]:
			print("{0}{1}{2}".format(self.color("blue"), self.errormsg, self.color("end")))
	try:
		try:
			soup = BeautifulSoup(html, "lxml")
		except:
			soup = BeautifulSoup(html, "html5lib")
		Cache.dataCache = soup.findAll("h3", {"class" : "r"})
		if len(Cache.dataCache) > 0:
			title = "{0}".format(Cache.dataCache[Cache.dataIndex].a)
			title = syscmd.delHtml(title)
			string = "{0}: {1}".format(title, Cache.dataCache[Cache.dataIndex].a.get('href'))
			self.send_chan(string)
			Cache.dataIndex += 1
		else:
			self.send_chan("No results for: {0}".format(parameters))
	except Exception as e:
		self.errormsg = "[ERROR]-[google] googleSearch()(2) stating: {0}".format(e)
		sysErrorLog.log( self ) ## LOG the error
		if self.config["debug"]:
			print("{0}{1}{2}".format(self.color("red"), self.errormsg, self.color("end")))
Example #7
0
File: fmi.py Project: jasuka/pyBot
def fmi( self ):

	if len(self.msg) == 5 and "set" in self.msg[4]:
		self.send_chan( "Usage: !fmi <city> | !fmi set <city>" )
		return
	## For saving the city
	if len(self.msg) == 6:
		if "set" in self.msg:
			city = self.msg[5]
			setCity( self, city )
			self.send_notice( "Your city {0} has been saved!".format(city.title().strip()))
		else:
			self.send_chan( "Usage: !fmi <city> | !fmi set <city>" )
	else:
		try:
			if len(self.msg) == 4:	## when called only with !fmi, see if the city is saved
				city = getCity( self )
				if not city and len(self.msg) == 5:
					city = self.msg[4]
			if len(self.msg) == 5:
				city = self.msg[4].strip() #With !fmi City
			## If no city saved and no parameter
			if not city:
				self.send_chan( "Usage: !fmi <city> | !fmi set <city>" )
				return
		except IndexError:
			self.send_chan( "Usage: !fmi <city> | !fmi set <city>" )
			raise
			
		if "set" not in city and syscmd.checkCity( self, city ): # We don't want to look for a city named "set"
			
			city = city.title().strip()
			parameter = urllib.parse.quote(city)
			url = "http://ilmatieteenlaitos.fi/saa/" + parameter
			
			if city == "Oulu":
				url = "http://ilmatieteenlaitos.fi/saa/" + parameter + "?&station=101799"
			if city == "Helsinki":
				url = "http://ilmatieteenlaitos.fi/saa/" + parameter + "?&station=100971"
			if city == "Kilpisjärvi":
				url = "http://ilmatieteenlaitos.fi/saa/enonteki%C3%B6/" + parameter
			if city == "Kuusamo":
				url = "http://ilmatieteenlaitos.fi/saa/" + parameter + "?&station=101886"
	
			#html = syscmd.getHtml(self, url, True )
			driver = webdriver.PhantomJS()
			driver.get(url)
			html = driver.page_source
 
			try:
				soup = BeautifulSoup(html, "lxml")
				text = ""
				if "Varasivu" in soup.title.string:
					self.send_chan("~ Ilmatieteen laitoksen sivustolla on ongelmia - http://vara.fmi.fi/")
				else:
					## When the weather was updated
					time = soup.findAll("h2", {"id" : "latest-observations"})
					if time:
						time = time[0].string[-5:]

					names = soup.findAll("span", {"class" : "parameter-name"})
					string = soup.findAll("span", {"class" : "parameter-value"})
					feels = soup.findAll("tr", {"class" : "meteogram-apparent-temperatures"})
					rain = soup.findAll("div", {"class" : "probability-of-precipitation"})
					rainAmount = soup.findAll("tr", {"class" : "meteogram-hourly-precipitation-values"})
					warnings = soup.findAll("span", {"class" : "advisory-type"})

					if rainAmount:
						rainAmount = rainAmount[0].td.span.get('title')
						rainAmount = rainAmount[27:]
						
					## If FMI happens to return the feel temperatures..
					if feels:
					 feels = "{0}".format(feels[0].td.div.get('title'))
					else:
						feels = "0°C"

					## Loop the reusts into a string
					for index, element in enumerate(string):
						if index == 1 and rainAmount and feels and rain:
							text += " - {0}{1}".format(feels[4:-1].capitalize(),"C")
							text += " - Sateen todennäköisyys {0} ({1})".format(rain[0].span.string, rainAmount)

						text += " - {0} {1}".format(names[index], element)
					text = text[3:-7] #Strip leading crap and some </spa from the end

					## See if there's warnings
					if warnings:
						text += " - Varoitus: {0}".format(warnings[0].string)

					## Remove the Html tags
					if text:	
						trimmed = syscmd.delHtml(text)
						output = "{0} klo {1}: {2}".format(city.strip(), time, trimmed)
						self.send_chan( output )
					else:
						self.send_chan("An error occured getting the weather data")
			except Exception as e:
				self.errormsg = "[ERROR]-[fmi] fmi() stating: {0}".format(e)
				sysErrorLog.log( self ) ## LOG the error
				if self.config["debug"]:
					print("{0}{1}{2}".format(self.color("red"), self.errormsg, self.color("end")))
		else:
			self.send_chan( "City {0} doesn't exist!".format(city.title().strip()) )