@@ -35,8 +35,8 @@ class Reddit:
3535 """
3636
3737 _ACCESS_TOKEN_URL = "https://www.reddit.com/api/v1/access_token"
38- _SUBREDDIT_SUBMISSIONS_URL = "https://oauth.reddit.com/r/{subreddit}/{sort}"
39- _USER_SUBMISSIONS_URL = "https://oauth.reddit.com/user/{user}/submitted"
38+ _SUBREDDIT_ARTICLES_URL = "https://oauth.reddit.com/r/{subreddit}/{sort}"
39+ _USER_ARTICLES_URL = "https://oauth.reddit.com/user/{user}/submitted"
4040 _AUTH_EXPIRY_OVERHEAD_NS = 60_000_000_000
4141
4242 def __init__ (
@@ -50,39 +50,39 @@ def __init__(
5050 self ._access_token_expires_in = 0
5151 self ._logger = getLogger (__name__ )
5252
53- async def subreddit_submissions (
53+ async def subreddit_articles (
5454 self , subreddit : str , limit : int , sort : SortType
5555 ) -> list [dict [str , Any ]]:
56- """Get a list of Reddit submissions from the given subreddit
56+ """Get a list of Reddit articles from the given subreddit
5757
5858 Args:
59- subreddit (str): subreddit to load submissions from
60- limit (int): up to how many submissions should be loaded
61- sort (SortType): sort type to use when loading submissions
59+ subreddit (str): subreddit to load articles from
60+ limit (int): up to how many articles should be loaded
61+ sort (SortType): sort type to use when loading articles
6262
6363 Returns:
64- list[Submission ]: list of loaded submissions from the given subreddit
64+ list[dict[str, Any ]: list of loaded articles from the given subreddit
6565 """
66- self ._logger .info (f"Loading subreddit submissions [{ subreddit } ] [{ limit } ] [{ sort .name } ]" )
67- url = self ._SUBREDDIT_SUBMISSIONS_URL .format (subreddit = subreddit , sort = sort .name .lower ())
66+ self ._logger .info (f"Loading subreddit articles [{ subreddit } ] [{ limit } ] [{ sort .name } ]" )
67+ url = self ._SUBREDDIT_ARTICLES_URL .format (subreddit = subreddit , sort = sort .name .lower ())
6868 params = {"limit" : limit }
69- return await self ._get_submissions (url , params )
69+ return await self ._get_articles (url , params )
7070
71- async def user_submissions (self , user : str , limit : int , sort : SortType ) -> list [dict [str , Any ]]:
72- """Get a list of Reddit submissions from the given Reddit user
71+ async def user_articles (self , user : str , limit : int , sort : SortType ) -> list [dict [str , Any ]]:
72+ """Get a list of Reddit articles from the given Reddit user
7373
7474 Args:
75- user (str): Reddit user to load submissions from
76- limit (int): up to how many submissions should be loaded
77- sort (SortType): sort type to use when loading submissions
75+ user (str): Reddit user to load articles from
76+ limit (int): up to how many articles should be loaded
77+ sort (SortType): sort type to use when loading articles
7878
7979 Returns:
80- list[Submission ]: list of loaded submissions from the Reddit user
80+ list[dict[str, Any ]: list of loaded articles from the Reddit user
8181 """
82- self ._logger .info (f"Loading user submissions [{ user } ] [{ limit } ] [{ sort .name } ]" )
83- url = self ._USER_SUBMISSIONS_URL .format (user = user )
82+ self ._logger .info (f"Loading user articles [{ user } ] [{ limit } ] [{ sort .name } ]" )
83+ url = self ._USER_ARTICLES_URL .format (user = user )
8484 params = {"limit" : limit , "sort" : sort .name .lower ()}
85- return await self ._get_submissions (url , params )
85+ return await self ._get_articles (url , params )
8686
8787 async def _authorize (self ) -> None :
8888 self ._logger .info ("Authorizing" )
@@ -103,18 +103,18 @@ async def _request_access_token(self) -> Response:
103103 headers = self ._auth_headers ,
104104 )
105105
106- async def _get_submissions (self , url : str , params : dict [str , Any ]) -> list [dict [str , Any ]]:
106+ async def _get_articles (self , url : str , params : dict [str , Any ]) -> list [dict [str , Any ]]:
107107 if self ._access_token_expires_in <= time_ns ():
108108 self ._logger .info ("Access token expired, requesting new one" )
109109 await self ._authorize ()
110- response = await self ._request_submissions (url , params )
110+ response = await self ._request_articles (url , params )
111111 if response .status_code in [401 , 403 ]:
112112 self ._logger .info (f"Response returned code [{ response .status_code } ], re-authorizing" )
113113 await self ._authorize ()
114- response = await self ._request_submissions (url , params )
114+ response = await self ._request_articles (url , params )
115115 response .raise_for_status ()
116- return [submission ["data" ] for submission in response .json ()["data" ]["children" ]]
116+ return [article ["data" ] for article in response .json ()["data" ]["children" ]]
117117
118- async def _request_submissions (self , url : str , params : dict [str , Any ]) -> Response :
118+ async def _request_articles (self , url : str , params : dict [str , Any ]) -> Response :
119119 async with AsyncClient () as client :
120120 return await client .get (url = url , params = params , headers = self ._auth_headers )
0 commit comments