[reddit] support sorting options and sub-options (#15)
Example:
https://www.reddit.com/r/<subreddit>/top/?sort=top&t=month
(the 'sort=top' parameter is irrelevant and can be omitted)
This commit is contained in:
@@ -199,8 +199,8 @@ class DeviantartFavoriteExtractor(DeviantartExtractor):
|
||||
r"(?:/((\d+)/([^/?]+)|\?catpath=/))?"]
|
||||
test = [
|
||||
("http://rosuuri.deviantart.com/favourites/58951174/Useful", {
|
||||
"url": "6a10e8e05401d61696ecf7a54c174e1c8ece7ba1",
|
||||
"keyword": "44fe61c5b20db8d90d4e06b86346630289f1db7d",
|
||||
"url": "65d070eae215b9375b4437a1ab4659efdad204e3",
|
||||
"keyword": "e5f3aaf35274e976ae81c5b151e650eea1dde775",
|
||||
}),
|
||||
("http://h3813067.deviantart.com/favourites/", {
|
||||
"url": "71345ce3bef5b19bd2a56d7b96e6b5ddba747c2e",
|
||||
|
||||
@@ -69,14 +69,18 @@ class RedditExtractor(Extractor):
|
||||
class RedditSubredditExtractor(RedditExtractor):
|
||||
"""Extractor for images from subreddits on reddit.com"""
|
||||
subcategory = "subreddit"
|
||||
pattern = [r"(?:https?://)?(?:m\.|www\.)?reddit\.com/r/([^/]+)/?$"]
|
||||
pattern = [r"(?:https?://)?(?:m\.|www\.)?reddit\.com/r/([^/?&#]+)"
|
||||
r"(/[a-z]+)?/?"
|
||||
r"(?:\?.*?(?:\bt=([a-z]+))?)?$"]
|
||||
|
||||
def __init__(self, match):
|
||||
RedditExtractor.__init__(self)
|
||||
self.subreddit = match.group(1)
|
||||
self.subreddit, self.order, self.timeframe = match.groups()
|
||||
|
||||
def submissions(self):
|
||||
return self.api.submissions_subreddit(self.subreddit)
|
||||
subreddit = self.subreddit + (self.order or "")
|
||||
params = {"t": self.timeframe} if self.timeframe else {}
|
||||
return self.api.submissions_subreddit(subreddit, params)
|
||||
|
||||
|
||||
class RedditSubmissionExtractor(RedditExtractor):
|
||||
@@ -111,10 +115,11 @@ class RedditAPI():
|
||||
return (submission["data"]["children"][0]["data"],
|
||||
self._unfold(comments))
|
||||
|
||||
def submissions_subreddit(self, subreddit):
|
||||
def submissions_subreddit(self, subreddit, params):
|
||||
"""Collect all (submission, comments)-tuples of a subreddit"""
|
||||
endpoint = "/r/" + subreddit + "/.json"
|
||||
params = {"raw_json": 1, "limit": 100}
|
||||
params["raw_json"] = 1
|
||||
params["limit"] = 100
|
||||
return self._pagination(endpoint, params)
|
||||
|
||||
def authenticate(self):
|
||||
@@ -130,7 +135,6 @@ class RedditAPI():
|
||||
"grant_type": "https://oauth.reddit.com/grants/installed_client",
|
||||
"device_id": "DO_NOT_TRACK_THIS_DEVICE",
|
||||
}
|
||||
self.log.info("Requesting access token")
|
||||
response = self.session.post(url, data=data, auth=(client_id, ""))
|
||||
if response.status_code != 200:
|
||||
raise exception.AuthenticationError()
|
||||
|
||||
Reference in New Issue
Block a user