示例#1
0
        return json.loads(body)

    def get_image(self, query):
        q = {
          "v": "1.0",
          "rsz": "8",
          "q": query,
          "safe": "active",
          "imgtype": "face"
        }
        images = self.get_json(q)
        images = images["responseData"]["results"]
        if images:
            image = random.choice(images)
            return image["unescapedUrl"]

    def work(self):
        unread_messages = self.get_unread_messages()
        for msg in unread_messages:
            body = msg.Body.encode("ascii", "replace")
            match = re.match(r"!(?:mo?u)?sta(?:s|c)he?(?: me)? (.*)", body,
                      re.I)
            if match:
                style = int(random.random() * 5)
                image = match.group(1)
                if not image.startswith("http"):
                    image = self.get_image(image)
                msg.Chat.SendMessage(self.mustache_url.format(style, image))

pluginapi.register_plugin(MustachifyMePlugin)
示例#2
0
class TodaysJokePlugin(pluginapi.Plugin):

    headers = {"User-agent": "Today's Joke"}
    url = "http://www.reddit.com/r/Jokes/top/?sort=top&t=day"

    def work(self):
        unread_messages = self.get_unread_messages()
        for msg in unread_messages:
            body = msg.Body.encode('ascii', 'replace')
            if body == "!joke":
                title, content = None, None

                req = urllib2.Request(self.url, headers=self.headers)
                con = urllib2.urlopen(req)
                page = BeautifulSoup(con.read())
                title_tag = page.find("a", "title")
                title = unicode(title_tag.string).upper()

                submission_url = "http://www.reddit.com" + title_tag["href"]
                req = urllib2.Request(submission_url, headers=self.headers)
                con = urllib2.urlopen(req)
                page = BeautifulSoup(con.read())
                expando = page.find("div", "expando")
                ps = expando.find_all("p")
                content = u"\n".join([unicode(p.get_text()) for p in ps])

                msg.Chat.SendMessage(title + u"\n" + content)

pluginapi.register_plugin(TodaysJokePlugin)
示例#3
0
import pluginapi


class TemplatePlugin(pluginapi.Plugin):

    def work(self):
        unread_messages = self.get_unread_messages()
        for msg in unread_messages:
            body = msg.Body.encode('ascii', 'replace')
            pass  # Do something with body of message ...

pluginapi.register_plugin(TemplatePlugin)
示例#4
0
        with open(self._table_file, 'w') as table_file:
            for key, value in self._table.items():
                table_file.write("{0} {1}\n".format(key, value))

    def __init__(self, skype):
        pluginapi.Plugin.__init__(self, skype)
        self._table_file = os.path.dirname(__file__) + os.sep + "table.txt"
        self._table = {}
        self._load_table()

    def work(self):
        unread_messages = self.get_unread_messages()
        for msg in unread_messages:
            body = msg.Body.encode('ascii', 'replace')
            commands = {
                "^!karma (\w+)$":    self._get_karma,
                "^(\w+)\+\+$": self._inc_karma,
                "^(\w+)\-\-$": self._dec_karma,
            }
            for command, function in commands.items():
                match = re.match(command, body)
                if match:
                    reply = function(match.group(1).lower())
                    if reply:
                        msg.Chat.SendMessage(reply)

    def __del__(self):
        self._save_table()

pluginapi.register_plugin(KarmaPlugin)
示例#5
0
    """Call weather service for curent location weather"""
    def getWeather(self,address):

        fullLocName,lat,lng = self.getLoaction(address)
        
        if fullLocName != None:
            webWeather = ServerCaller("https://api.forecast.io/forecast/0e75783f8a3fa4de5b49fff8115d93b4/"+str(lat)+","+str(lng))
            webWeather.callService()
            
            currently = Weather("Currently",webWeather.data["currently"])   
            return currently.getWeatherInfo(fullLocName)
        
        else:
            return "(wtf) - 404 Location not found!"

    def work(self):
        
        unread_messages = self.get_unread_messages()
        
        for msg in unread_messages:
            body = msg.Body.encode('utf-8', 'replace')
            if "!weather" in body:
                if "!weather" == body:
                    msg.Chat.SendMessage("No search location found! (shake)")
                else:
                    address = body[len("!weather")+1:]
                    msg.Chat.SendMessage(self.getWeather(address))

pluginapi.register_plugin(TellMeWeatherPlugin)