Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
elebumm
GitHub Repository: elebumm/RedditVideoMakerBot
Path: blob/master/utils/id.py
493 views
1
import re
2
from typing import Optional
3
4
from utils.console import print_substep
5
6
7
def extract_id(reddit_obj: dict, field: Optional[str] = "thread_id"):
8
"""
9
This function takes a reddit object and returns the post id
10
"""
11
if field not in reddit_obj.keys():
12
raise ValueError(f"Field '{field}' not found in reddit object")
13
reddit_id = re.sub(r"[^\w\s-]", "", reddit_obj[field])
14
return reddit_id
15
16