Пример #1
0
 def testBadAuthenticate(self):
     api = Api(BLOG, USER, 'badpassword')
     try:
         api.auth_check()
         assert False  # should never get here
     except TumblrAuthError, e:
         pass
Пример #2
0
 def testBadAuthenticate(self):
     api = Api(BLOG, USER, 'badpassword' )
     try:
         api.auth_check()
         assert False # should never get here    
     except TumblrAuthError,  e:
         pass
Пример #3
0
def command_quote(bot, user, channel, args):
    if has_pymblr is None:
        boy.say(channel, "Tumblr module not running.")
        return

    new_args = args.split(" ")

    tag_args = filter(lambda arg: arg[0] == "#", new_args)

    real_args = filter(lambda arg: arg[0] != "#", new_args)

    # remove hash
    tag_args = [arg[1:] for arg in tag_args]

    print "real args: %s\ntag args: %s" % (real_args, tag_args)

    if len(real_args) == 1:
        # quote a single person
        last_said = bot.channel_log.last_said(channel, real_args[0]).to_string()
        if last_said != None:
            try:
                api = Api(config["tumblr_group"], config["tumblr_email"], config["tumblr_password"])
                post = api.write_regular(body=cgi.escape(last_said), tags=tag_args, slug="quote")
                print "Quoted %s as %s" % (bot.factory.getNick(user), post["url"])
                bot.say(channel, "Your quote: %s" % post["url"])
            except TumblrError, e:
                bot.say(channel, "That quote didn't go through because Tumblr returned a temporary error.")
            except Exception, e:
                # bot.say(channel, "Something horrible happened.")
                print e
Пример #4
0
    def handle_url(self, message, reply_to, url, sender, times=0):
        new_args = message.strip().split(' ')

        tag_args = filter(
            lambda arg: len(arg) > 0 and arg[0] == '#', new_args
        )

        real_args = filter(
            lambda arg: len(arg) > 0 and arg[0] != '#', new_args
        )

        filtered_msg = ' '.join(real_args).replace(url, '').replace(':', '')

        times = times + 1

        nick = nm_to_n(sender)
        ops = self.bot.channels[self.bot.channel].opers()
        voiced = self.bot.channels[self.bot.channel].voiced()
        if hasattr(self, 'require_voice') and \
            (nick not in voiced and nick not in ops):
            return
        if hasattr(self, 'require_ops') and \
            nick not in ops:
            return

        api = Api(self.tumblog, self.email, self.password)
        caption = '%s\nvia %s' % (filtered_msg, nick)

        def print_result(result):
            try:
                print "%s posted a %s to %s" % (nick, result['type'],
                    result['url'])
            except:
                print "Call result: %s" % repr(result)

        try:
            try:
                urls = api.readurls()
                if url not in api.readurls():
                    self.bot.set_callback(api.autopost_url, print_result,
                        args=(url, caption, tag_args))
            except BrowserStateError:
                # Skipping because of a mechanize error.
                return
            except URLError:
                return

        except TumblrError, e:
            return
            if (times < 3):
                print e
                print "Error encountered, trying it again."
                # try it again, a couple of times.
                sleep(3)
                self.handle_url(self, message, reply_to, url, sender,
                    times=times)
            else:
                print e
Пример #5
0
    def handle_url(self, message, reply_to, url, sender, times=0):
        new_args = message.strip().split(' ')

        tag_args = filter(
            lambda arg: len(arg) > 0 and arg[0] == '#', new_args
        )

        real_args = filter(
            lambda arg: len(arg) > 0 and arg[0] != '#', new_args
        )

        filtered_msg = ' '.join(real_args).replace(url, '').replace(':', '')

        times = times + 1
        print "Attempting to post %s for the #%i time" % (url, times)
        nick = nm_to_n(sender)
        api = Api(self.tumblog, self.email, self.password)
        if self.bot.settings['anonymous_channel']:
            caption = '%s\nvia %s' % (filtered_msg, nick)
        else:
            caption = '' # don't leak usernames or what is said

        def print_result(result):
            print result
            print type(result)
            try:
                print "%s posted a %s to %s" % (nick, result['type'],
                    result['url'])
            except:
                print "Call result: %s" % repr(result)

        try:
            try:
                urls = api.readurls()
                if url not in api.readurls():
                    self.bot.set_callback(api.autopost_url, print_result,
                        args=(url, caption, tag_args))
            except BrowserStateError:
                # Skipping because of a mechanize error.
                return
            except URLError:
                return

        except TumblrError, e:
            return
            if (times < 3):
                print e
                print "Error encountered, trying it again."
                # try it again, a couple of times.
                sleep(3)
                self.handle_url(self, message, reply_to, url, sender,
                    times=times)
            else:
                print e
Пример #6
0
    def testFixNames(self):
        api = Api(BLOG)
        before = {}
        before['test_one'] = 1
        before['test_two'] = 1

        after = api._fixnames(before)
        assert not 'test_one' in after
        assert 'test-one' in after

        assert 'test-two' in after
        assert not 'test_two' in after
Пример #7
0
    def testFixNames(self):
        api = Api(BLOG)
        before = {}
        before['test_one'] = 1 
        before['test_two'] = 1 

        after = api._fixnames(before)
        assert not 'test_one' in after
        assert 'test-one' in after

        assert 'test-two' in after
        assert not 'test_two' in after
Пример #8
0
    def handle_url(self, message, reply_to, url, sender, times=0):
        new_args = message.strip().split(' ')
        
        tag_args = filter(
            lambda arg: len(arg) > 0 and arg[0] == '#'
            ,new_args
        )

        real_args = filter(
            lambda arg: len(arg) > 0 and arg[0] != '#'
            ,new_args
        ) 

        filtered_msg = ' '.join(real_args).replace(url,'').replace(':','')

        times = times + 1
        print "Attempting to post %s for the #%i time" % (url, times)
        nick = nm_to_n(sender)
        api = Api(self.tumblog, self.email, self.password)
        caption = '%s\nvia %s' % (filtered_msg, nick)
        def print_result(result):
            print result
            print type(result)
            try:
                print "%s posted a %s to %s" % (nick, result['type'], result['url'])
            except:
                print "Call result: %s" % repr(result)

        try:
            try:
                urls = api.readurls()
                if url not in api.readurls():
                    self.bot.set_callback(api.autopost_url, print_result,
                        args=(url, caption, tag_args))
            except BrowserStateError:
                # Skipping because of a mechanize error.
                return
            except URLError:
                return

        except TumblrError, e:
            return
            if (times < 3):
                print e
                print "Error encountered, trying it again."
                # try it again, a couple of times.
                sleep(3)
                self.handle_url(self, message, reply_to, url, sender, times=times)
            else:
                print e
Пример #9
0
 def testRead(self):
     api = Api(BLOG)
     freq = {}
     posts = api.read()
     total = 0
     for post in posts:
         total += 1
         type = post['type']
         try:
             freq[type] += 1
         except:
             freq[type] = 1
     assert total > 0
     for type in freq:
         assert self.countType(api, type) == freq[type]
Пример #10
0
 def testRead(self):
     api = Api(BLOG)
     freq = {}
     posts = api.read()
     total = 0
     for post in posts:
         total += 1
         type = post['type']
         try:
             freq[type] += 1
         except:
             freq[type] = 1
     assert total > 0
     for type in freq:
         assert self.countType(api,type) == freq[type]
Пример #11
0
def command_tumbl(bot, user, channel, args):

    new_args = args.split(" ")

    tag_args = filter(lambda arg: arg[0] == "#", new_args)

    real_args = filter(lambda arg: arg[0] != "#", new_args)

    try:
        api = Api(config["tumblr_group"], config["tumblr_email"], config["tumblr_password"])
        post = api.write_regular(
            body=cgi.escape(" ".join(real_args) + "\nposted by %s" % bot.factory.getNick(user)), tags=tag_args
        )
        print "%s posted some text to Tumblr. %s" % (bot.factory.getNick(user), post["url"])
        bot.say(channel, "Your post: %s" % post["url"])
    except TumblrError, e:
        bot.say(channel, "Your post didn't go through.  Feel free to try again, champ.")
        print e
Пример #12
0
 def testRequiredArgs(self):
     api = Api(BLOG, USER, PASSWORD)
     self.assertRaises(TumblrError, api.write_regular)
     self.assertRaises(TumblrError, api.write_quote)
     self.assertRaises(TumblrError, api.write_photo)
     self.assertRaises(TumblrError,
                       api.write_photo,
                       source='foo',
                       data='bar')
     self.assertRaises(TumblrError, api.write_conversation)
     self.assertRaises(TumblrError, api.write_link)
     self.assertRaises(TumblrError, api.write_video)
Пример #13
0
def handle_url(bot, user, channel, url, msg, times=0):
    if has_pymblr is None:
        return

    new_args = msg.split(" ")

    tag_args = filter(lambda arg: arg[0] == "#", new_args)

    real_args = filter(lambda arg: arg[0] != "#", new_args)

    filtered_msg = " ".join(real_args).replace(url, "").replace(":", "")

    times = times + 1
    print "Attempting to post %s for the #%i time" % (url, times)
    config["exclude_users"] = []
    if channel not in config["exclude_channels"] and user not in config["exclude_users"]:
        nick = bot.factory.getNick(user)
        api = Api(config["tumblr_group"], config["tumblr_email"], config["tumblr_password"])
        caption = "%s\nvia %s" % (filtered_msg, nick)
        try:
            try:
                urls = api.readurls()
                if url not in api.readurls():
                    post = api.autopost_url(url, caption, tag_args)
                    print "%s posted a %s to %s" % (nick, post["type"], post["url"])
            except TumblrError:
                post = api.autopost_url(url, caption, tag_args)
                print "%s posted a %s to %s" % (nick, post["type"], post["url"])

        except TumblrError, e:
            if times < 4:
                print e
                print "Error encountered, trying it again."
                # try it again, a couple of times.
                sleep(5)
                handle_url(bot, user, channel, url, msg, times)
            else:
                print e
Пример #14
0
 def do_quote(self, message, reply_to):
     new_args = message.strip().split(' ')
     user = new_args[0]
     tag_args = filter(
         lambda arg: len(arg) > 0 and arg[0] == '#'
         ,new_args
     )
     real_args = filter(
         lambda arg: len(arg) > 0 and arg[0] != '#'
         ,new_args
     )
     # remove hash
     tag_args = [arg[1:] for arg in tag_args]
     
     print "real args: %s\ntag args: %s" % (real_args, tag_args)
     
     if len(real_args) == 1:
         # quote a single person
         last_said = self.bot.log[reply_to][user][-1].strip()
         if last_said != None:
             try:
                 api = Api(self.tumblog, self.email, self.password)
                 kwargs = {
                     'body': cgi.escape(last_said),
                     'tags': tag_args,
                     'slug': 'quote'
                     }
                 def print_result(result):
                     try:    
                         print "Quoted %s as %s to %s" % (user,
                             result['url'], repr(reply_to))
                     except:
                         print 'Could not quote: %s' % result
                 
                 self.bot.set_callback(api.write_regular,
                     print_result, kwargs=kwargs)
                 
                 #bot.say(channel, "Your quote: %s" % post['url'])
             except TumblrError, e:
                 self.bot.connection.privmsg(reply_to, "Tumblr posting " + \
                 "failed due to a temporary error.")
                 print TumblrError, e
             except Exception, e:
                 #bot.say(channel, "Something horrible happened.")
                 print e
Пример #15
0
                post = api.write_regular(body=cgi.escape(last_said), tags=tag_args, slug="quote")
                print "Quoted %s as %s" % (bot.factory.getNick(user), post["url"])
                bot.say(channel, "Your quote: %s" % post["url"])
            except TumblrError, e:
                bot.say(channel, "That quote didn't go through because Tumblr returned a temporary error.")
            except Exception, e:
                # bot.say(channel, "Something horrible happened.")
                print e
    elif len(real_args) == 2:
        # Post an entire exchange
        exchange = bot.channel_log.exchange_set(channel, user, int(real_args[0]) + 1, int(real_args[1]))
        lines = [cgi.escape(item.to_string()) for item in exchange]
        lines.reverse()
        full_text = "<br />\n".join(lines)
        try:
            api = Api(config["tumblr_group"], config["tumblr_email"], config["tumblr_password"])
            post = api.write_regular(body=full_text, tags=tag_args, slug="quote")
            print "Posted exchange as %s" % (post["url"])
            bot.say(channel, "Your post: %s" % post["url"])
        except TumblrError, e:
            bot.say(
                channel,
                "That quote didn't work because of a temporary issue with Tumblr.  Make sure you adjust the line offset if you try this again.",
            )
        except Exception, e:
            # bot.say(channel, "Something horrible happened.")
            print e


def handle_url(bot, user, channel, url, msg, times=0):
    if has_pymblr is None:
Пример #16
0
    def testWrite(self):
        api = Api(BLOG, USER, PASSWORD)

        newpost = api.write_regular('title', 'body')
        post = api.read(newpost['id'])
        assert newpost['id'] == post['id']

        newpost = api.write_link('http://www.google.com')
        post = api.read(newpost['id'])
        assert newpost['id'] == post['id']

        newpost = api.write_quote('it was the best of times...')
        post = api.read(newpost['id'])
        assert newpost['id'] == post['id']

        newpost = api.write_conversation('me: wow\nyou: double wow!')
        post = api.read(newpost['id'])
        assert newpost['id'] == post['id']

        newpost = api.write_video('http://www.youtube.com/watch?v=60og9gwKh1o')
        post = api.read(newpost['id'])
        assert newpost['id'] == post['id']

        newpost = api.write_photo(
            'http://www.google.com/intl/en_ALL/images/logo.gif')
        post = api.read(newpost['id'])
        assert newpost['id'] == post['id']
Пример #17
0
 def testAuthenticate(self):
     api = Api(BLOG, USER, PASSWORD )
     api.auth_check()
Пример #18
0
    def testWrite(self):
        api = Api(BLOG, USER, PASSWORD)

        newpost = api.write_regular('title','body')
        post = api.read(newpost['id'])
        assert newpost['id'] == post['id']
Пример #19
0
 def testAuthenticate(self):
     api = Api(BLOG, USER, PASSWORD)
     api.auth_check()