fix(reddit): use removeprefix("r/") for subreddit names, not lstrip("r/")
str.lstrip("r/") treats its argument as a character set, stripping
leading r and / repeatedly. Subreddits starting with 'r' (e.g. r/robotics,
r/ruby) were silently mangled to 'obotics' / 'uby'. Replace with
str.removeprefix("r/") at all four call sites. Python 3.9+ pattern is
safe here — project requires 3.12. Closes #288.
Co-authored-by: Alex Key <alexanderkey0508@gmail.com>
This commit is contained in:
@@ -388,7 +388,7 @@ def subrun_kwargs_for(
|
|||||||
|
|
||||||
subreddits = _choose("subreddits", "subreddits")
|
subreddits = _choose("subreddits", "subreddits")
|
||||||
if isinstance(subreddits, list):
|
if isinstance(subreddits, list):
|
||||||
subreddits = [s.strip().lstrip("r/") for s in subreddits if s.strip()] or None
|
subreddits = [s.strip().removeprefix("r/") for s in subreddits if s.strip()] or None
|
||||||
|
|
||||||
x_related = plan_entry.get("x_related")
|
x_related = plan_entry.get("x_related")
|
||||||
if isinstance(x_related, list):
|
if isinstance(x_related, list):
|
||||||
@@ -625,7 +625,7 @@ def main() -> int:
|
|||||||
depth = "deep" if args.deep else "quick" if args.quick else "default"
|
depth = "deep" if args.deep else "quick" if args.quick else "default"
|
||||||
try:
|
try:
|
||||||
x_related = [h.strip() for h in args.x_related.split(",") if h.strip()] if args.x_related else None
|
x_related = [h.strip() for h in args.x_related.split(",") if h.strip()] if args.x_related else None
|
||||||
subreddits = [s.strip().lstrip("r/") for s in args.subreddits.split(",") if s.strip()] if args.subreddits else None
|
subreddits = [s.strip().removeprefix("r/") for s in args.subreddits.split(",") if s.strip()] if args.subreddits else None
|
||||||
tiktok_hashtags = [h.strip().lstrip("#") for h in args.tiktok_hashtags.split(",") if h.strip()] if args.tiktok_hashtags else None
|
tiktok_hashtags = [h.strip().lstrip("#") for h in args.tiktok_hashtags.split(",") if h.strip()] if args.tiktok_hashtags else None
|
||||||
tiktok_creators = [c.strip().lstrip("@") for c in args.tiktok_creators.split(",") if c.strip()] if args.tiktok_creators else None
|
tiktok_creators = [c.strip().lstrip("@") for c in args.tiktok_creators.split(",") if c.strip()] if args.tiktok_creators else None
|
||||||
ig_creators = [c.strip().lstrip("@") for c in args.ig_creators.split(",") if c.strip()] if args.ig_creators else None
|
ig_creators = [c.strip().lstrip("@") for c in args.ig_creators.split(",") if c.strip()] if args.ig_creators else None
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ def _extract_subreddits(reddit_items: List[Dict[str, Any]]) -> List[str]:
|
|||||||
|
|
||||||
for item in reddit_items:
|
for item in reddit_items:
|
||||||
# Primary subreddit
|
# Primary subreddit
|
||||||
sub = item.get("subreddit", "").strip().lstrip("r/")
|
sub = item.get("subreddit", "").strip().removeprefix("r/")
|
||||||
if sub:
|
if sub:
|
||||||
sub_counts[sub] += 1
|
sub_counts[sub] += 1
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ def search(
|
|||||||
encoded_query = _url_encode(query)
|
encoded_query = _url_encode(query)
|
||||||
|
|
||||||
if subreddit:
|
if subreddit:
|
||||||
sub = subreddit.lstrip("r/").strip()
|
sub = subreddit.removeprefix("r/").strip()
|
||||||
url = (
|
url = (
|
||||||
f"https://www.reddit.com/r/{sub}/search.json"
|
f"https://www.reddit.com/r/{sub}/search.json"
|
||||||
f"?q={encoded_query}&restrict_sr=on&sort=relevance&t=month&limit={limit}&raw_json=1"
|
f"?q={encoded_query}&restrict_sr=on&sort=relevance&t=month&limit={limit}&raw_json=1"
|
||||||
|
|||||||
Reference in New Issue
Block a user