Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import urllib2
import json
last_timestamp_utc = 0
reddit_api = ''
page_request = urllib2.urlopen(reddit_api)
page_content = json.loads(
posts = page_content['data']['children']
# API results are in order of newest to oldest, but we want to
# itterate over them from oldest to newest, so we reverse the
# order of the list here
# Check each post in the list of posts the API gave us
for i in posts:
# Skip posts from before our last post timestamp
if i['data']['created_utc'] <= last_timestamp_utc:
#print "Skipped: Presumably old post: " + str(i['data']['created_utc'])
# Skip posts that are marked NSFW
if i['data']['over_18']:
#print "Skipped: Post is NSFW"
# Skip if the post is a meta post
if i['data']['is_self']:
#print "Skipped: Post is metapost (self)"
post_url = i['data']['url']
#print 'Valid post url: ' + post_url
print post_url
last_timestamp_utc = i['data']['created_utc']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment