def test_submiss2(self):
     stemming = reddit.client().submission(id='8mj3f6')
     self.assertDictEqual(
         ResultatenSubmisser().submiss(stemming), {
             'template': 'resultaten',
             'title':
             'Resultaten Stemming Tweede Kamer over M0309 t/m M0311, W0125',
             'flair': 'UITSLAGEN',
             'invalid_votes': 0,
             'opkomst_percentage': 96,
             'results': {
                 'M0309': {
                     -1: 2,
                     0: 0,
                     1: 22
                 },
                 'M0310': {
                     -1: 7,
                     0: 1,
                     1: 16
                 },
                 'M0311': {
                     -1: 8,
                     0: 0,
                     1: 16
                 }
             },
             'date': '27-05-2018',
             'submissions': {
                 'M0309': None,
                 'M0310': None,
                 'M0311': Submission(reddit.client(), id='8m3sph')
             },
         })
Пример #2
0
def main():
    last_stemming = next(reddit.client().subreddit('rmtk').search(
        'flair:"' + sys.argv[1] + '"', limit=1, sort='new'))
    results = ResultatenSubmisser().submiss(last_stemming)

    text = Template(
        open('templates/submissions/resultaten.md').read()).render(results)

    reddit.client().subreddit(sys.argv[2]).submit(results['title'], text)
 def test_get_vote_format3(self):
     submission = reddit.client().submission(id='8ktghf')
     format = StemmingHelper.get_format(submission.selftext)
     self.assertEqual(
         format, {
             'M0295', 'M0296', 'M0297', 'M0298', 'M0299', 'M0300', 'M0301',
             'M0302', 'M0303', 'M0304', 'M0305', 'M0306', 'M0307', 'M0308',
             'W0124'
         })
Пример #4
0
 def test_not_voted_on2(self):
     comment = reddit.client().comment(id="dzfj0ws")
     response = StemmingResponder().respond(comment)
     self.assertDictEqual(
         response, {
             'template': 'stemming',
             'not_in_voting': set(),
             'not_voted_on': {'M0295'},
             'incorrect_keyword': set()
         })
 def test_submiss1(self):
     stemming = reddit.client().submission(id='8mj4nz')
     self.assertDictEqual(
         ResultatenSubmisser().submiss(stemming), {
             'template': 'resultaten',
             'title': 'Resultaten Stemming Eerste Kamer over W0124',
             'flair': 'UITSLAGEN',
             'invalid_votes': 0,
             'opkomst_percentage': 88,
             'results': {
                 'W0124': {
                     -1: 0,
                     0: 0,
                     1: 7
                 }
             },
             'date': '27-05-2018',
             'submissions': {
                 'W0124': Submission(reddit.client(), id='8b6nkk')
             },
         })
 def test_get_votes3(self):
     comment = reddit.client().comment(id="dsppe6c")
     votes = StemmingHelper.get_votes(comment.body)
     self.assertDictEqual(votes, {'M0283': 1, 'M0284': 0, 'M0285': 1})
 def test_get_votes2(self):
     comment = reddit.client().comment(id="dznyp21")
     votes = StemmingHelper.get_votes(comment.body)
     self.assertDictEqual(votes, {'M0309': 1, 'M0310': -1, 'M0311': -1})
 def test_get_vote_format2(self):
     submission = reddit.client().submission(id='8mj3f6')
     format = StemmingHelper.get_format(submission.selftext)
     self.assertEqual(format, {'M0309', 'M0310', 'M0311'})
 def test_get_vote_format1(self):
     submission = reddit.client().submission(id='8oag4a')
     format = StemmingHelper.get_format(submission.selftext)
     self.assertEqual(format, {'M0312', 'M0313', 'W0125-I', 'W0126'})
Пример #10
0
 def test_no_vote_at_all(self):
     comment = reddit.client().comment(id="dzrpoad")
     response = StemmingResponder().respond(comment)
     self.assertIsNone(response)
Пример #11
0
 def test_follows_format3(self):
     comment = reddit.client().comment(id="e041767")
     response = StemmingResponder().respond(comment)
     self.assertIsNone(response)
Пример #12
0
def main():
    responders = [
        VoorzitterResponder(),
        StemmingResponder(),
        EKResponder(),
        EKTKResponder(),
        TKResponder()
    ]

    for comment in reddit.client().subreddit('rmtk').stream.comments():
        try:
            comment.refresh()

            if isinstance(comment, MoreComments):
                continue
            if comment.body and ("meta" in comment.body.lower()
                                 or comment.body == '[deleted]'):
                continue

            if comment.author and comment.author.name in [
                    'AutoRMTK', 'AutoModerator'
            ]:
                continue

            responses = [
                response for response in
                [responder.respond(comment) for responder in responders]
                if response != None
            ]

            if len(responses) < 1:
                continue

            rendered_responses = [
                Template(
                    open('templates/responses/' + r['template'] +
                         '.md').read()).render(r) for r in responses
            ]

            response_text = Template(
                open('templates/response.md').read()).render(
                    rendered_responses=rendered_responses)

            debug_permalink = comment.permalink

            prev = [
                c for c in comment.replies.list()
                if c and not isinstance(c, MoreComments) and c.author
                and c.author.name == 'AutoRMTK'
            ]

            if prev:
                prev[0].edit(response_text)
            else:
                comment.reply(response_text)
        except Exception as e:
            print(e)
            print('*****')

            client = Client(os.getenv('SENTRY_URL'))
            client.captureException()

            continue
 def assert_flair_being_used(self, flair):
     submissions = reddit.client().subreddit('rmtk').search('flair:"' +
                                                            flair + '"',
                                                            limit=1)
     self.assertEqual(len(list(submissions)), 1, msg=flair)
Пример #14
0
 def find_kamerstuk_submission(kamerstuk: str):
     return next(
         (s for s in reddit.client().subreddit('rmtk').search(kamerstuk)
             if s.link_flair_text in [submission_types.MOTIE, submission_types.WETSVOORSTEL]),
         None
     )