| Name | Description | Package | Version | |----------------------------|------------------------------------------------------------------|---------|---------| | Reddit.SubmitTextPost | Submit a text-based post to a subreddit | Reddit | 0.0.1 | | Reddit.CommentOnPost | Comment on a Reddit post | Reddit | 0.0.1 | | Reddit.ReplyToComment | Reply to a Reddit comment | Reddit | 0.0.1 | | Reddit.GetPostsInSubreddit | Gets posts titles, links, and other metadata in the specified subreddit | Reddit | 0.0.1 | | Reddit.GetContentOfPost | Get the content (body) of a Reddit post by its identifier. | Reddit | 0.0.1 | | Reddit.GetContentOfMultiplePosts | Get the content (body) of multiple Reddit posts by their identifiers. | Reddit | 0.0.1 | | Reddit.GetTopLevelComments | Get the first page of top-level comments of a Reddit post. | Reddit | 0.0.1 | ### Why not use an SDK? Reddit API does not have an official SDK, although [PRAW](https://github.com/praw-dev/praw) has large community support. I played around with PRAW, but ultimately decided to not use an SDK. PRAW made it incredibly easy to work with Reddit Objects, but there were a few drawbacks that ultimately swayed me to not use it: 1. PRAW assumes that it will do the auth for you. A client ID and secret must be passed to PRAW, but a tool only has the auth token. I was able to hack around this by manipulating private properties - but it felt too hacky 2. PRAW does not support Python 3.13 3. PRAW is not async. There is [AsyncPRAW](https://github.com/praw-dev/asyncpraw), but the community does not look active there.
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from enum import Enum
|
|
|
|
|
|
class SubredditListingType(str, Enum):
|
|
HOT = "hot"
|
|
NEW = "new"
|
|
RISING = "rising"
|
|
TOP = "top" # time-based
|
|
CONTROVERSIAL = "controversial" # time-based
|
|
|
|
def is_time_based(self) -> bool:
|
|
return self in [SubredditListingType.TOP, SubredditListingType.CONTROVERSIAL]
|
|
|
|
|
|
class RedditTimeFilter(str, Enum):
|
|
NOW = "NOW"
|
|
TODAY = "TODAY"
|
|
THIS_WEEK = "THIS_WEEK"
|
|
THIS_MONTH = "THIS_MONTH"
|
|
THIS_YEAR = "THIS_YEAR"
|
|
ALL_TIME = "ALL_TIME"
|
|
|
|
def to_api_value(self) -> str:
|
|
_map = {
|
|
RedditTimeFilter.NOW: "hour",
|
|
RedditTimeFilter.TODAY: "day",
|
|
RedditTimeFilter.THIS_WEEK: "week",
|
|
RedditTimeFilter.THIS_MONTH: "month",
|
|
RedditTimeFilter.THIS_YEAR: "year",
|
|
RedditTimeFilter.ALL_TIME: "all",
|
|
}
|
|
return _map[self]
|
|
|
|
|
|
class RedditThingType(str, Enum):
|
|
"""The type of a Reddit 'thing'.
|
|
|
|
Typically used as a prefix for fullnames, e.g. t1_1234567890
|
|
is the fullname of a comment with id 1234567890
|
|
"""
|
|
|
|
COMMENT = "t1"
|
|
ACCOUNT = "t2"
|
|
LINK = "t3"
|
|
MESSAGE = "t4"
|
|
SUBREDDIT = "t5"
|
|
AWARD = "t6"
|