Beispiel #1
0
 def test_id_from_url__invalid_urls(self):
     urls = [
         '', '1', '/', 'my.it/2gmzqe', 'http://my.it/_',
         'https://redd.it/_/', 'http://reddit.com/comments/_/2gmzqe'
     ]
     for url in urls:
         with pytest.raises(ClientException):
             Submission.id_from_url(url)
Beispiel #2
0
 def test_id_from_url__invalid_urls(self):
     urls = ['', '1', '/', 'my.it/2gmzqe',
             'http://my.it/_',
             'https://redd.it/_/',
             'http://reddit.com/comments/_/2gmzqe']
     for url in urls:
         with pytest.raises(ClientException):
             Submission.id_from_url(url)
Beispiel #3
0
 def test_id_from_url__invalid_urls(self):
     urls = [
         "",
         "1",
         "/",
         "my.it/2gmzqe",
         "http://my.it/_",
         "https://redd.it/_/",
         "http://reddit.com/comments/_/2gmzqe",
         "https://reddit.com/r/wallpapers/",
         "https://reddit.com/r/wallpapers",
     ]
     for url in urls:
         with pytest.raises(ClientException):
             Submission.id_from_url(url)
Beispiel #4
0
 def test_id_from_url__invalid_urls(self):
     urls = [
         "",
         "1",
         "/",
         "my.it/2gmzqe",
         "http://my.it/_",
         "https://redd.it/_/",
         "http://reddit.com/comments/_/2gmzqe",
         "https://reddit.com/r/wallpapers/",
         "https://reddit.com/r/wallpapers",
     ]
     for url in urls:
         with pytest.raises(ClientException):
             Submission.id_from_url(url)
Beispiel #5
0
 def test_id_from_url(self):
     urls = ['http://my.it/2gmzqe',
             'https://redd.it/2gmzqe',
             'http://reddit.com/comments/2gmzqe',
             'https://www.reddit.com/r/redditdev/comments/2gmzqe/'
             'praw_https_enabled_praw_testing_needed/']
     for url in urls:
         assert Submission.id_from_url(url) == '2gmzqe', url
Beispiel #6
0
 def test_id_from_url(self):
     urls = [
         'http://my.it/2gmzqe', 'https://redd.it/2gmzqe',
         'http://reddit.com/comments/2gmzqe',
         'https://www.reddit.com/r/redditdev/comments/2gmzqe/'
         'praw_https_enabled_praw_testing_needed/'
     ]
     for url in urls:
         assert Submission.id_from_url(url) == '2gmzqe', url
Beispiel #7
0
 def test_id_from_url(self):
     urls = [
         "http://my.it/2gmzqe",
         "https://redd.it/2gmzqe",
         "https://redd.it/2gmzqe/",
         "http://reddit.com/comments/2gmzqe",
         "https://www.reddit.com/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/",
         "https://www.reddit.com/gallery/2gmzqe",
     ]
     for url in urls:
         assert Submission.id_from_url(url) == "2gmzqe", url
Beispiel #8
0
def process_removal(removal_action, reddit: reddit):
    c.execute('SELECT * FROM pendingposts WHERE submission_id=?',
              (Submission.id_from_url('https://reddit.com' +
                                      removal_action.target_permalink), ))

    # If post is pending now, don't bother
    if c.fetchone():
        return

    print('Removal detected. Updating database...')
    c.execute('UPDATE posts SET removed=1 WHERE url=?',
              (removal_action.target_permalink, ))
    conn.commit()
    process_comment.update_wiki(reddit)
Beispiel #9
0
    def register_comment(self, entry_dict):
        submission_short_id = Submission.id_from_url(entry_dict['link'])
        comment_author = entry_dict['author']['name'][3:]
        comment_date = self._get_comment_date(entry_dict['updated'])

        with closing(self.db.cursor()) as cur:
            # create row to initialize counter then increment
            cur.execute(
                """
                INSERT INTO comment(submission_id, user_name, comment_date)
                    VALUES(%s, %s, %s)
                ON CONFLICT ON CONSTRAINT comment_pkey
                    DO NOTHING;

                    UPDATE comment SET comment_count = comment_count + 1
                    WHERE submission_id=%s AND user_name=%s AND comment_date=%s;
            """, (submission_short_id, comment_author, comment_date,
                  submission_short_id, comment_author, comment_date))
            self.db.commit()
Beispiel #10
0
def delete_post(con, id_type, from_reddit, post_id):
    submissions = con.meta.tables["submissions"]

    use_reddit = id_type == "submission"

    if not use_reddit:
        submission_id = post_id

        query = sql.select([submissions.c.reddit_id]).where(
            submissions.c.id == submission_id
        )
        row = con.db.execute(query).first()

        if row is None:
            log.error("Submission %s does not exist", submission_id)
            return

        reddit_id = row["reddit_id"]
    else:
        reddit_id = post_id

        if val.url(reddit_id):
            reddit_id = Submission.id_from_url(reddit_id)

    if from_reddit and reddit_id:
        sub = con.reddit.submission(reddit_id)

        sub.delete()

        sub.comments.replace_more(limit=None)

        for comment in sub.comments.list():
            if comment.author == con.reddit.user.me():
                comment.delete()

    query = submissions.update().values(reddit_id=None, submitted_on=None)
    if use_reddit:
        query = query.where(submissions.c.reddit_id == reddit_id)
    else:
        query = query.where(submissions.c.id == submission_id)

    con.db.execute(query)
Beispiel #11
0
def _check_removal_required(submission: Submission,
                            cfg: Config) -> Tuple[bool, bool]:
    """
    Check whether the submission has to be removed and whether this is reported.

    Note that this function returns a Tuple of booleans, where the first
    is to signify whether the submission is to be removed and the latter
    whether a relevant report was issued for this decision.
    """
    for item in submission.user_reports:
        if item[0] and any(reason in item[0] for reason in (
                reports.original_post_deleted_or_locked,
                reports.post_violates_rules,
        )):
            return True, True
    linked_submission = cfg.r.submission(submission.id_from_url(
        submission.url))
    if is_removed(linked_submission):
        return True, False
    return False, False