Ashley Felton committed 915c3e6

Tweaked reddit_swfporn_urls() function to allow return of json.

  • Participants
  • Parent commits 049e95e

Comments (0)

Files changed (1)


-def reddit_sfwporn_urls(ups=200):
+def reddit_sfwporn_urls(ups=200, json_data=False):
     Returns a list of Imgur URLs to image files posted to the Reddit SFWPorn network,
     with at least ``ups`` number of upvotes.
     Won't guarantee that all URLs are valid, but most should be.
+    If ``json_data`` is passed in as True, JSON will be returned instead of URLs list.
     imgur = []
     r = urllib.urlopen(REDDIT_SFWPORN_URL)
     for d in j['data']['children']:
         data = d['data']
         if 'imgur' in data['url'] and data['ups'] >= ups:
-            imgur.append(data['url'])
+            if json_data:
+                imgur.append(data)
+            else:
+                imgur.append(data['url'])
+    if json_data:
+        return imgur
     # Cleanse the URLs.
     for k, v in enumerate(imgur):
         u = list(urlparse.urlparse(v))