diff --git a/modules/randomreddit.py b/modules/randomreddit.py deleted file mode 100644 index d477620..0000000 --- a/modules/randomreddit.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python3 -""" -randomreddit.py - return a random reddit url from a subreddit's frontpage -author: andreim -""" - -import web -import re -import json -from tools import GrumbleError -from random import choice - - -def randomreddit(phenny, input): - - subreddit = input.group(2) - if not subreddit: - phenny.say(".random - get a random link from the subreddit's frontpage") - return - - if not re.match('^[A-Za-z0-9_-]*$',subreddit): - phenny.say(input.nick + ": bad subreddit format.") - return - - - url = "http://www.reddit.com/r/" + subreddit + "/.json" - try: - resp = web.get(url) - except: - try: - resp = web.get(url) - except: - try: - resp = web.get(url) - except: - raise GrumbleError('Reddit or subreddit unreachable.') - - try: - reddit = json.loads(resp) - post = choice(reddit['data']['children']) - except: - raise GrumbleError('Error parsing response from Reddit.') - - nsfw = False - if post['data']['over_18']: - nsfw = True - - if nsfw: - phenny.reply("!!NSFW!! " + post['data']['url'] + " (" + post['data']['title'] + ") !!NSFW!!") - else: - phenny.reply(post['data']['url'] + " (" + post['data']['title'] + ")") - -randomreddit.commands = ['random'] -randomreddit.priority = 'medium' -randomreddit.thread = False diff --git a/modules/test/test_randomreddit.py b/modules/test/test_randomreddit.py deleted file mode 100644 index 6337356..0000000 --- a/modules/test/test_randomreddit.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -test_randomredit.py - tests for the randomreddit module -author: mutantmonkey -""" - -import re -import unittest -from mock import MagicMock, Mock -from modules.randomreddit import randomreddit - - -class TestRandomreddit(unittest.TestCase): - def setUp(self): - self.phenny = MagicMock() - - def test_randomreddit(self): - input = Mock(group=lambda x: 'vtluug') - randomreddit(self.phenny, input) - - out = self.phenny.reply.call_args[0][0] - m = re.match('^http://.+? \(.*\)$', - out, flags=re.UNICODE) - self.assertTrue(m)