Skip to content

Commit d8c6e94

Browse files
Rename "submission" to article
1 parent cc1f3e1 commit d8c6e94

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Flake8](https://github.com/Electronic-Mango/reddit-python-api/actions/workflows/flake8.yml/badge.svg)](https://github.com/Electronic-Mango/reddit-api-api/actions/workflows/flake8.yml)
66
[![PyPI version](https://badge.fury.io/py/reddit-python-api.svg)](https://badge.fury.io/py/reddit-python-api)
77

8-
A simple read-only Reddit Python API allowing access to both subreddit and user submissions, build with [`httpx`](https://www.python-httpx.org/).
8+
A simple read-only Reddit Python API allowing access to both subreddit and user articles, build with [`httpx`](https://www.python-httpx.org/).
99

1010

1111

@@ -17,10 +17,10 @@ A simple read-only Reddit Python API allowing access to both subreddit and user
1717
* [Reddit app & configuration](#reddit-app--configuration)
1818
* [Usage](#usage)
1919
* [Create the API](#create-the-api)
20-
* [Get a list of submissions in a subreddit](#get-a-list-of-submissions-in-a-subreddit)
21-
* [Get a list of user submissions](#get-a-list-of-user-submissions)
20+
* [Get a list of articles in a subreddit](#get-a-list-of-articles-in-a-subreddit)
21+
* [Get a list of user articles](#get-a-list-of-user-articles)
2222
* [Sort types](#sort-types)
23-
* [Returned submissions type](#returned-submissions-type)
23+
* [Returned articles type](#returned-articles-type)
2424

2525

2626

@@ -32,13 +32,13 @@ Python version at least `3.10` is required.
3232
Full list of Python requirements is in `requirements.txt` file.
3333

3434
No additional API wrapper was used (like [PRAW](https://github.com/praw-dev/praw)), Reddit API is accessed directly.
35-
It should be much faster when accessing a list of submissions.
35+
It should be much faster when accessing a list of articles.
3636

3737
No data is stored.
3838
**Reddit is accessed in `read-only` mode.**
3939

4040

41-
Currently, this API allows access to submissions in either subreddits or from users.
41+
Currently, this API allows access to articles in either subreddits or from users.
4242
It doesn't access comments.
4343

4444

@@ -85,17 +85,17 @@ reddit = Reddit("your client ID", "your app secret", "custom user agent")
8585
```
8686

8787

88-
### Get a list of submissions in a subreddit
88+
### Get a list of articles in a subreddit
8989

9090
```python
9191
reddit = Reddit("your client ID", "your app secret")
92-
# reddit.subreddit_submissions("subreddit name", load_count, sort_type)
93-
submissions = reddit.subreddit_submissions("Python", 10, SortType.HOT)
92+
# reddit.subreddit_articles("subreddit name", load_count, sort_type)
93+
articles = reddit.subreddit_articles("Python", 10, SortType.HOT)
9494
```
9595
First argument is a name of a subreddit.
9696

97-
Second argument specifies how many submissions should be loaded.
98-
API can return lower number if there are fewer submissions in a given subreddit than provided.
97+
Second argument specifies how many articles should be loaded.
98+
API can return lower number if there are fewer articles in a given subreddit than provided.
9999

100100
Third argument specifies sort type.
101101
Following sort types are supported:
@@ -108,12 +108,12 @@ SortType.CONTROVERSIAL
108108
```
109109

110110

111-
### Get a list of user submissions
111+
### Get a list of user articles
112112

113113
```python
114114
reddit = Reddit("your client ID", "your app secret")
115-
# reddit.user_submissions("username", load_count, sort_type)
116-
submissions = reddit.user_submissions("spez", 20, SortType.CONTROVERSIAL)
115+
# reddit.user_articles("username", load_count, sort_type)
116+
articles = reddit.user_articles("spez", 20, SortType.CONTROVERSIAL)
117117
```
118118
General usage is the same as for subreddits.
119119

@@ -130,17 +130,17 @@ SortType.CONTROVERSIAL
130130
```
131131

132132

133-
### Returned submissions type
133+
### Returned articles type
134134

135-
Returned type is a list of submissions, where each submission is a `dict`/`json` directly returned by official Reddit API.
135+
Returned type is a list of articles, where each article is a `dict`/`json` directly returned by official Reddit API.
136136

137137
You can check official Reddit API documentation for:
138138
* users - https://www.reddit.com/dev/api/#GET_user_{username}_submitted
139139
* subreddits - https://www.reddit.com/dev/api/#GET_hot (and other endpoints for different sort types)
140140

141141
Returned dicts are [`listings`](https://www.reddit.com/dev/api/#listings) directly from official Reddit API.
142-
Submission contents are quite long, but I've left their additional parsing the user.
143-
Here is an example of one submission dict:
142+
Article contents are quite long, but I've left their additional parsing the user.
143+
Here is an example of one article dict:
144144
```python
145145
{
146146
'approved_at_utc': None,

redditpythonapi/reddit.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)