def trig_ffml(self, bot, source, target, trigger, argument): """Kommando för att visa anekdoter från www.fanformittliv.com""" # Sanitize argument argument = argument.strip().lower() argument = utility.asciilize(argument) if argument: m = re.match("http:\/\/www\.fanformittliv\.com\/\w+\/(\d+)", argument) result = "" # Show all types, if requested if argument == 'visa_typer': result = "Tillgängliga typer: " + ", ".join(self.types) # If the argument is a valid type, look it up elif (argument in self.types) or (argument.isdigit()): result = fml_entry(argument, "se") elif m: result = fml_entry(m.group(1), "se") if result: # Return result (encoded to make IRCClient.send() happy) return result.encode('utf-8', 'replace') # Non-valid argument return self.usage
def trig_temp(self, bot, source, target, trigger, argument): """ Usage: .temp [City] Uses data from temperature.nu, please direct all complaints to www.temperatur.nu """ argument = argument.strip() if argument: argument = argument.strip() self.places[source] = argument self.save() else: if source in self.places: argument = self.places[source] else: argument = "ryd" argument_text = argument argument = utility.asciilize(argument) argument = utility.escape(argument) # awesome hack to include avesta! if argument.lower() == "avesta": actual_argument = "fors" else: actual_argument = argument url = "http://www.temperatur.nu/termo/%s/temp.txt" % actual_argument.lower() response = utility.read_url(url) m = None if response: data = response["data"] m = _get_temp_re.match(data) if m and m.group(1) != "not found": return "Temperature in %s: %s." % (argument_text, m.group(1)) else: return "Temperature in %s: invalid place, try using .yr instead." % (argument_text)
def trig_mat(self, bot, source, target, trigger, argument): """Hämtar dagens (eller en annan dags) meny från vald restaurangs hemsida.""" # Split arguments argument = argument.strip() args = argument.split(' ', 2) # Determine location and day if (not argument) or (len(args) > 2): return "Prova med \".mat plats [dag]\" - de platser jag känner till är: " + \ "HG, VilleValla, Kårallen, Zenit" # TODO automatically generated list? elif len(args) == 1: day = MatCommand.days[datetime.now().isoweekday()-1].lower() else: day = args[1].lower() location = utility.asciilize(args[0]).lower() # Do stuff if location == "liu": return liu_food_str(day) else: return food_str(location, day)
def trig_temp(self, bot, source, target, trigger, argument): """ Usage: .temp [City] Uses data from temperature.nu, please direct all complaints to www.temperatur.nu """ argument = argument.strip() if argument: argument = argument.strip() self.places[source] = argument self.save() else: if source in self.places: argument = self.places[source] else: argument = 'ryd' argument_text = argument argument = utility.asciilize(argument) argument = utility.escape(argument) # awesome hack to include avesta! if argument.lower() == "avesta": actual_argument = "fors" else: actual_argument = argument url = "http://www.temperatur.nu/termo/%s/temp.txt" % actual_argument.lower( ) response = utility.read_url(url) m = None if response: data = response["data"] m = _get_temp_re.match(data) if m and m.group(1) != "not found": return "Temperature in %s: %s." % (argument_text, m.group(1)) else: return "Temperature in %s: invalid place, try using .yr instead." % ( argument_text)