Created
July 27, 2012 03:18
-
-
Save leegao/3185998 to your computer and use it in GitHub Desktop.
Burgers
This file contains hidden or 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
| import json, urllib2 | |
| def perma(o): | |
| return "http://www.reddit.com/r/%s/comments/%s/lol/%s?context=3"%(o['subreddit'],o['link_id'].replace('t3_',''),o['id']) | |
| def q(): | |
| req = urllib.Request("http://reddit.com/r/askreddit/comments/.json", headers={"User-Agent":"Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"}) | |
| return json.loads(urllib2.urlopen(req).read()) | |
| def find(listing, func): | |
| l = listing['data']['children'] | |
| return filter(lambda o: func(o['data']), l) | |
| def exact_match_by_username(username): | |
| def func(o): | |
| return o['author'].lower().find(username.lower()) > 0 | |
| return func | |
| def exact_match_by_content(keywords): | |
| def func(o): | |
| return any([o['body'].lower().find(keyword.lower()) > 0 for keyword in keywords]) | |
| return func | |
| def at_least_length(n): | |
| def func(o): | |
| return len(o['body']) >= n | |
| return func | |
| def any_filter(l): | |
| def func(o): | |
| return any([f(o) for f in l]) | |
| return func | |
| def all_filter(l): | |
| def func(o): | |
| return all([f(o) for f in l]) | |
| return func | |
| import time | |
| while True: | |
| lst = q() | |
| okay = find(lst, exact_match_by_username("burger")) + find(lst, exact_match_by_content(["burger", "fast food"])) | |
| okay = list(set(okay)) | |
| for comment in okay: | |
| print perma(comment['data']) | |
| time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment