예제 #1
0
def main(args):
    parser = argparse.ArgumentParser(description='Test a redditbot')
    parser.add_argument('file', type=file, help='file to use')
    parser.add_argument('--debug', action='store_true', default=False)
    parser.add_argument('--username', type=str, help='username to run with')
    parser.add_argument('--password', type=str, help='password to run with')
    parser.add_argument('--sandbox', action='store_true', default=False, help='Run the bot inside the RestrictedPython sandbox')

    options = parser.parse_args(args[1:])
    if options.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    class TestBox(redditbots.TestingSandbox):
        def username(self):
            return options.username
        def password(self):
            return options.password

    class SecureTestBox(redditbots.BotSandbox):
        def username(self):
            return options.username
        def password(self):
            return options.password

    if options.sandbox:
        botManager = redditbots.BotManager(SecureTestBox)
    else:
        botManager = redditbots.BotManager(TestBox)
    botManager.loadBot(options.file)
    botManager.triggerInit()

    r = botManager.getReddit()

    try:
        while True:
            r_all = r.get_subreddit('all').get_new_by_date()

            print "Processing new submissions in /r/all"
            for post in r_all:
                botManager.triggerNewSubmission(post)

            print "Processing new comments"
            for comment in r.get_all_comments():
                botManager.triggerNewComment(comment)

            nextProcess = 0
            while nextProcess < sys.maxint and nextProcess >= 0:
                nextProcess = botManager.processReplyQueue()
                now = monoclock.nano_count()/1000000000
                print "Processing replies in %i seconds"%(nextProcess-now)
                if nextProcess-now > 1:
                    time.sleep(nextProcess-now)
    except urllib2.URLError, e:
        print "Network error:", e
예제 #2
0
    def test_nano_count_getsBigger(self):
        values = []
        for n in range(10000):
            values.append(monoclock.nano_count())

        # Values either get bigger or stay the same
        self.assertEqual(values, sorted(values))

        # None of the values should be the same
        self.assertEqual(len(values), len(set(values)))
예제 #3
0
	def test_nano_count_getsBigger(self):
		values = []
		for n in xrange(10000):
			values.append(monoclock.nano_count())

		# Values either get bigger or stay the same
		self.assertEqual(values, sorted(values))

		# None of the values should be the same
		self.assertEqual(len(values), len(set(values)))
예제 #4
0
 def processReplyQueue(self):
     now = monoclock.nano_count()/1000000000
     if now > self._nextReplyTime:
         for pair in self._replyQueue:
             post, reply = pair
             self.login()
             try:
                 ret = post.reply(reply)
                 self._replyQueue.remove(pair)
             except RateLimitExceeded, e:
                 print "Rate limit exceeded, waiting another 10 minutes."
             self._nextReplyTime = now+60*10
             return self._nextReplyTime
예제 #5
0
 def test_wrongArguments(self):
     self.assertRaises(TypeError, lambda: monoclock.nano_count(1))
     self.assertRaises(TypeError, lambda: monoclock.nano_count(None))
     self.assertRaises(TypeError, lambda: monoclock.nano_count([]))
     self.assertRaises(TypeError, lambda: monoclock.nano_count({}))
     self.assertRaises(TypeError, lambda: monoclock.nano_count(keyword=1))
예제 #6
0
 def test_nano_count_isCorrectType(self):
     val1 = monoclock.nano_count()
     # In reality it is really always a long, I think.
     self.assertTrue(isinstance(val1, int))
예제 #7
0
	def test_wrongArguments(self):
		self.assertRaises(TypeError, lambda: monoclock.nano_count(1))
		self.assertRaises(TypeError, lambda: monoclock.nano_count(None))
		self.assertRaises(TypeError, lambda: monoclock.nano_count([]))
		self.assertRaises(TypeError, lambda: monoclock.nano_count({}))
		self.assertRaises(TypeError, lambda: monoclock.nano_count(keyword=1))
예제 #8
0
	def test_nano_count_isCorrectType(self):
		val1 = monoclock.nano_count()
		# In reality it is really always a long, I think.
		self.assertTrue(isinstance(val1, (int, long)))
예제 #9
0
import monoclock

t = monoclock.nano_count()
t = t/1000000 
print t