Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last id #42

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions redditdownload/reddit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
"""Return list of items from a sub-reddit of reddit.com."""

import logging
import sys
from urllib2 import urlopen, Request, HTTPError
from json import JSONDecoder
Expand All @@ -15,6 +16,9 @@ def getitems(subreddit, multireddit=False, previd='', reddit_sort=None):
:param reddit_sort: type of sorting post
:returns: list -- list of post url
"""
# assume no advanced sorting.
logger = logging.getLogger(__name__)
is_advanced_sort = False

if multireddit:
if '/m/' not in subreddit:
Expand Down Expand Up @@ -73,6 +77,8 @@ def getitems(subreddit, multireddit=False, previd='', reddit_sort=None):
# check if url have already query
if '?' in url.split('/')[-1] and is_advanced_sort:
url += '&'
elif not is_advanced_sort:
pass # fix '?' on simple sort
else: # url dont have query yet
url += '?'

Expand All @@ -81,6 +87,7 @@ def getitems(subreddit, multireddit=False, previd='', reddit_sort=None):
url += 'sort={}&t={}'.format(sort_type, sort_time_limit)

try:
logger.debug('url[{}]'.format(url))
req = Request(url, headers=hdr)
json = urlopen(req).read()
data = JSONDecoder().decode(json)
Expand Down
2 changes: 1 addition & 1 deletion redditdownload/redditdownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def main():
if FINISHED:
break

LAST = ITEM['id'] if ITEM is not None else None
LAST = ITEMS[-1]['id'] if ITEMS[-1] is not None else None

print 'Downloaded {} files'.format(DOWNLOADED)
'(Processed {}, Skipped {}, Exists {})'.format(TOTAL, SKIPPED, ERRORS)
Expand Down