@@ -62,18 +62,12 @@ async def subreddit_submissions(
6262 Returns:
6363 list[Submission]: list of loaded submissions from the given subreddit
6464 """
65- self ._logger .info (
66- f"Loading subreddit submissions [{ subreddit } ] [{ limit } ] [{ sort .name } ]"
67- )
68- url = self ._SUBREDDIT_SUBMISSIONS_URL .format (
69- subreddit = subreddit , sort = sort .name .lower ()
70- )
65+ self ._logger .info (f"Loading subreddit submissions [{ subreddit } ] [{ limit } ] [{ sort .name } ]" )
66+ url = self ._SUBREDDIT_SUBMISSIONS_URL .format (subreddit = subreddit , sort = sort .name .lower ())
7167 params = {"limit" : limit }
7268 return await self ._get_submissions (url , params )
7369
74- async def user_submissions (
75- self , user : str , limit : int , sort : SortType
76- ) -> list [dict [str , Any ]]:
70+ async def user_submissions (self , user : str , limit : int , sort : SortType ) -> list [dict [str , Any ]]:
7771 """Get a list of Reddit submissions from the given Reddit user
7872
7973 Args:
@@ -97,9 +91,7 @@ async def _authorize(self) -> None:
9791 access_token = response_content ["access_token" ]
9892 self ._auth_headers ["Authorization" ] = f"Bearer { access_token } "
9993 expires_in = response_content ["expires_in" ] * 1_000_000_000
100- self ._access_token_expires_in = (
101- time_ns () + expires_in - self ._AUTH_EXPIRY_OVERHEAD_NS
102- )
94+ self ._access_token_expires_in = time_ns () + expires_in - self ._AUTH_EXPIRY_OVERHEAD_NS
10395
10496 async def _request_access_token (self ) -> Response :
10597 async with AsyncClient () as client :
@@ -110,23 +102,17 @@ async def _request_access_token(self) -> Response:
110102 headers = self ._auth_headers ,
111103 )
112104
113- async def _get_submissions (
114- self , url : str , params : dict [str , Any ]
115- ) -> list [dict [str , Any ]]:
105+ async def _get_submissions (self , url : str , params : dict [str , Any ]) -> list [dict [str , Any ]]:
116106 if self ._access_token_expires_in <= time_ns ():
117107 self ._logger .info ("Access token expired, requesting new one" )
118108 await self ._authorize ()
119109 response = await self ._request_submissions (url , params )
120110 if response .status_code in [401 , 403 ]:
121- self ._logger .info (
122- f"Response returned code [{ response .status_code } ], re-authorizing"
123- )
111+ self ._logger .info (f"Response returned code [{ response .status_code } ], re-authorizing" )
124112 await self ._authorize ()
125113 response = await self ._request_submissions (url , params )
126114 response .raise_for_status ()
127- return [
128- submission ["data" ] for submission in response .json ()["data" ]["children" ]
129- ]
115+ return [submission ["data" ] for submission in response .json ()["data" ]["children" ]]
130116
131117 async def _request_submissions (self , url : str , params : dict [str , Any ]) -> Response :
132118 async with AsyncClient () as client :
0 commit comments