Example #1
0
    def exchange_code_for_token(self, job):
        r = get_reddit_instance(refresh_token=job.refresh_token)

        logger.info("Step: Process code")
        refresh_token = r.auth.authorize(job.code)

        job.refresh_token = refresh_token
        job.state = Job.STATE_DELETING_COMMENTS
        job.save()
Example #2
0
    def delete_submissions(self, job):
        r = get_reddit_instance(refresh_token=job.refresh_token)

        submissions = r.user.me().submissions.new(limit=REDDIT_QUERY_LIMIT)

        logger.info("Step: Processing submissions")

        for submission in submissions:
            if submission.created_utc < calendar.timegm(job.started.utctimetuple()):
                job.submissions_deleted = job.submissions_deleted + 1
                if can_delete_content():
                    submission.delete()
                else:
                    logger.info("Not deleting. As this has not been enabled.")

                break
        else:
            logger.info("No submissions within timeframe")
            job.state = Job.STATE_FINISHED

        job.save()
Example #3
0
    def delete_comments(self, job):
        r = get_reddit_instance(refresh_token=job.refresh_token)

        comments = r.user.me().comments.new(limit=REDDIT_QUERY_LIMIT)

        logger.info("Step: Processing comments")

        for comment in comments:
            if comment.created_utc < calendar.timegm(job.started.utctimetuple()):
                job.comments_deleted = job.comments_deleted + 1
                if can_delete_content():
                    comment.delete()
                else:
                    logger.info("Not deleting. As this has not been enabled.")

                break
        else:
            logger.info("No comments within timeframe")
            job.state = Job.STATE_DELETING_SUBMISSIONS

        job.save()
Example #4
0
 def test_instantiates(self):
     get_reddit_instance()
Example #5
0
 def test_raise_exception_if_not_configured(self):
     with self.assertRaises(Exception):
         get_reddit_instance()
Example #6
0
 def get_redirect_url(self, *args, **kwargs):
     r = get_reddit_instance()
     job = Job.objects.create()
     return r.auth.url(['history', 'identity', 'edit'], job.identifier, "permanent")