Created
February 1, 2017 06:19
-
-
Save brahmlower/c8b773bba72fc363241047970d6d575b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import urllib2 | |
import json | |
last_timestamp_utc = 0 | |
reddit_api = 'https://www.reddit.com/r/opendirectories/new.json?sort=new' | |
page_request = urllib2.urlopen(reddit_api) | |
page_content = json.loads(page_request.read()) | |
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 | |
posts.reverse() | |
# 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']) | |
continue | |
# Skip posts that are marked NSFW | |
if i['data']['over_18']: | |
#print "Skipped: Post is NSFW" | |
continue | |
# Skip if the post is a meta post | |
if i['data']['is_self']: | |
#print "Skipped: Post is metapost (self)" | |
continue | |
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