From fccc5ebe26d3f0b69696491df7529599b0044d10 Mon Sep 17 00:00:00 2001 From: Julien Pontoire Date: Wed, 9 Oct 2024 14:32:30 +0200 Subject: [PATCH] Adding functions to verify subreddit and user --- ural/reddit.py | 18 ++++++++++++++++++ ural/reddit.pyi | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ural/reddit.py b/ural/reddit.py index c4beba5..510421c 100644 --- a/ural/reddit.py +++ b/ural/reddit.py @@ -16,6 +16,24 @@ def is_reddit_url(url): return bool(re.match(REDDIT_URL_RE, url)) +def is_subreddit_url(url): + if not is_reddit_url(url): + return False + + return ( + '/r/' in url + ) + + +def is_reddit_user_url(url): + if not is_reddit_url(url): + return False + + return ( + '/user/' in url + ) + + def is_reddit_post_url(url): if not is_reddit_url(url): return False diff --git a/ural/reddit.pyi b/ural/reddit.pyi index 07569e4..4517a94 100644 --- a/ural/reddit.pyi +++ b/ural/reddit.pyi @@ -2,6 +2,8 @@ from typing import Optional from ural.types import AnyUrlTarget def is_reddit_url(url: str) -> bool : ... +def is_subreddit_url(url: str) -> bool : ... +def is_reddit_user_url(url: str) -> bool : ... def is_reddit_post_url(url: str) -> bool : ... -def convert_reddit_url_to_old_url(url: str) -> bool : ... -def convert_old_reddit_url_to_new_url(url: str) -> bool : ... \ No newline at end of file +def convert_reddit_url_to_old_url(url: str) -> str : ... +def convert_old_reddit_url_to_new_url(url: str) -> str : ... \ No newline at end of file