fix: re-review findings — os.system, truncation, recursion, swallowed errors

- Replace missed os.system() in posttextparser with subprocess.run
- Add truncate() after json.dump in videos.py save_data (trailing bytes bug)
- Replace exit() with sys.exit() in subreddit.py
- Add retry depth limit (50) to prevent infinite recursion in get_subreddit_threads
- Log search-scraping errors instead of silent except: pass in scraper.py

Co-Authored-By: RuFlo <ruv@ruv.net>
pull/2551/head
Hong Phuc 4 weeks ago
parent 64e9b6f149
commit 22868d5759

@ -559,8 +559,8 @@ def get_trending_threads_content(POST_ID: Optional[str] = None) -> dict:
for sp in search_posts:
if sp["post_id"] not in existing_ids:
posts.append(sp)
except Exception:
pass
except Exception as e:
print_substep(f"Search query failed: {e}", "yellow")
if not posts:
raise RuntimeError("No posts found in feed. Try again later.")

@ -1,4 +1,5 @@
import re
import sys
import praw
from praw.models import MoreComments
@ -105,11 +106,20 @@ def get_subreddit_threads(POST_ID: str):
submission = get_subreddit_undone(threads, subreddit)
if submission is None:
return get_subreddit_threads(POST_ID) # submission already done. rerun
# submission already done — retry with depth limit to prevent infinite recursion
if not hasattr(get_subreddit_threads, "_retry_depth"):
get_subreddit_threads._retry_depth = 0
get_subreddit_threads._retry_depth += 1
if get_subreddit_threads._retry_depth > 50:
raise RuntimeError("Exceeded retry limit (50) looking for an undone submission")
try:
return get_subreddit_threads(POST_ID)
finally:
get_subreddit_threads._retry_depth -= 1
elif not submission.num_comments and settings.config["settings"]["storymode"] == "false":
print_substep("No comments found. Skipping.")
exit()
sys.exit()
submission = check_done(submission) # double-checking

@ -1,5 +1,7 @@
import os
import re
import subprocess
import sys
import time
from typing import List
@ -30,7 +32,10 @@ def posttextparser(obj, *, tried: bool = False) -> List[str]:
nlp = spacy.load("en_core_web_sm")
except OSError as e:
if not tried:
os.system("python -m spacy download en_core_web_sm")
subprocess.run(
[sys.executable, "-m", "spacy", "download", "en_core_web_sm"],
check=False,
)
time.sleep(5)
return posttextparser(obj, tried=True)
print_step(

@ -60,6 +60,7 @@ def save_data(subreddit: str, filename: str, reddit_title: str, reddit_id: str,
done_vids.append(payload)
raw_vids.seek(0)
json.dump(done_vids, raw_vids, ensure_ascii=False, indent=4)
raw_vids.truncate()
def check_done_by_id(post_id: str) -> bool:

Loading…
Cancel
Save