Beispiel #1
0
 def __init__(self, irc):
     self.__parent = super(TraktTV, self)
     self.__parent.__init__(irc)
     self.db = TraktTVDB(dbfilename)
     world.flushers.append(self.db.flush)
     self.APIKEY = self.registryValue("apikey")
Beispiel #2
0
class TraktTV(callbacks.PluginRegexp):

    socket.setdefaulttimeout(60)

    SITEURL = "http://trakt.tv"
    APIURL = "http://api.trakt.tv"

    def __init__(self, irc):
        self.__parent = super(TraktTV, self)
        self.__parent.__init__(irc)
        self.db = TraktTVDB(dbfilename)
        world.flushers.append(self.db.flush)
        self.APIKEY = self.registryValue("apikey")

    def die(self):
        if self.db.flush in world.flushers:
            world.flushers.remove(self.db.flush)
        self.db.close()
        self.__parent.die()

    def setUserId(self, irc, msg, args, newId):
        """<id>

        Sets the TraktTV ID for the caller and saves it in a database.
        """

        self.db.set(msg.nick, newId)

        irc.reply("TraktTV ID changed.")
        #self.profile(irc, msg, args)

    set = wrap(setUserId, ["something"])

    def keyCheck(self, irc):
        if len(self.APIKEY) < 1:
            irc.reply("You can't use this command until you've set an API key!")
            return False
        else:
            return True

    def trendingMovies(self, irc, msg, args, wtf):
        """Get a list of movies trending right now"""

        if not self.keyCheck(irc):
            return False

        url = "%s/movies/trending.json/%s" % (self.APIURL, self.APIKEY)

        try:
           f = urllib2.urlopen(url)
        except urllib2.HTTPError, e:
            irc.error("Error: %s" % (e.code))
            print e.read()
            return

        data = simplejson.load(f)

        movies = 0
        for movie in data:
            movies += 1

            people = "people"
            if movie["watchers"] == 1:
                people = "person";

            are = "are"
            if movie["watchers"] == 1:
                are = "is"

            irc.reply(("%d %s %s now watching: %s (%d) | %s | %d%% | Trailer: %s" % ( movie["watchers"], people, are, movie["title"], movie["year"], movie["url"], movie["ratings"]["percentage"], movie["trailer"] )).encode("utf-8"))
            if movies >= 5:
                break