def main(): reddit = ReddiWrap(user_agent='made_this_up_quick') reddit.login('brainsareneat', 'isminus1') outfile = "graph.pkl" g = Graph(reddit, outfile) while True: g.update()
def main(): reddit = ReddiWrap(user_agent='made_this_up_quick') reddit.login('brainsareneat', 'isminus1') outfile = "graph.pkl" g = Graph(reddit, outfile) while True: g.update()
reddit = ReddiWrap(user_agent='ReddiWrap') USERNAME = '******' PASSWORD = '******' MOD_SUB = 'PipeTobacco' # A subreddit moderated by USERNAME # Load cookies from local file and verify cookies are valid reddit.load_cookies('cookies.txt') # If we had no cookies, or cookies were invalid, # or the user we are logging into wasn't in the cookie file: if not reddit.logged_in or reddit.user.lower() != USERNAME.lower(): print('logging into %s' % USERNAME) login = reddit.login(user=USERNAME, password=PASSWORD) if login != 0: # 1 means invalid password, 2 means rate limited, -1 means unexpected error print('unable to log in: %d' % login) print('remember to change USERNAME and PASSWORD') exit(1) # Save cookies so we won't have to log in again later reddit.save_cookies('cookies.txt') print('logged in as %s' % reddit.user) uinfo = reddit.user_info() print('\nlink karma: %d' % uinfo.link_karma) print('comment karma: %d' % uinfo.comment_karma)
import time import datetime from ReddiWrap import ReddiWrap import numpy as np reddit = ReddiWrap() # Create new instance of ReddiWrap login_result = reddit.login('brainsareneat', 'isminus1') if login_result != 0: # Anything other than '0' means an error occurred print 'unable to log in.' exit(1) olddict = {} newdict = {} clock = datetime.datetime a = clock.now() f = open("%s_%s_%srecord.csv" % (a.month, a.day, a.hour), "a") f.write("id, author, subreddit, title, created, link, url") b = clock.now() while b - a < datetime.timedelta(hours=6): print b - a time.sleep(1) new = reddit.get('/r/all/new') seen = False for post in new: entry = {"subreddit":post.subreddit.encode('ascii', 'ignore'), "link":post.permalink.encode('ascii', 'ignore'), "title":post.title.encode('ascii', 'ignore'),\ "created":post.created, "id":post.id, "url":post.url.encode('ascii', 'ignore'), "author":post.author.encode('ascii', 'ignore')}
reddit = ReddiWrap(user_agent='ReddiWrap') USERNAME = '******' PASSWORD = '******' MOD_SUB = 'PipeTobacco' # A subreddit moderated by USERNAME # Load cookies from local file and verify cookies are valid reddit.load_cookies('cookies.txt') # If we had no cookies, or cookies were invalid, # or the user we are logging into wasn't in the cookie file: if not reddit.logged_in or reddit.user.lower() != USERNAME.lower(): print('logging into %s' % USERNAME) login = reddit.login(user=USERNAME, password=PASSWORD) if login != 0: # 1 means invalid password, 2 means rate limited, -1 means unexpected error print('unable to log in: %d' % login) print('remember to change USERNAME and PASSWORD') exit(1) # Save cookies so we won't have to log in again later reddit.save_cookies('cookies.txt') print('logged in as %s' % reddit.user) uinfo = reddit.user_info() print('\nlink karma: %d' % uinfo.link_karma) print('comment karma: %d' % uinfo.comment_karma) # Retrieve posts in a subreddit
import time import datetime from ReddiWrap import ReddiWrap import numpy as np reddit = ReddiWrap() # Create new instance of ReddiWrap login_result = reddit.login('brainsareneat', 'isminus1') all_posts = [] new = reddit.get('/r/all/new') while True: time.sleep(1.5) for post in new: all_posts.append(post) posts= np.array(all_posts) np.savez('records.npz', posts = posts) new = reddit.get_next() print 'ok...'
import time import datetime from ReddiWrap import ReddiWrap import numpy as np reddit = ReddiWrap() # Create new instance of ReddiWrap login_result = reddit.login('ahoytestaccount', 'isminus1') try: postinfos = [item in np.load('text.npy')] indexed = [item in np.load('indexed.npy')] except: indexed = [] postinfos = [] while True: loaded = False while not loaded: #try: postholder = np.load('records.npz') posts = postholder['posts'] loaded = True #except: time.sleep(3) print "failed" first_time = posts[0].created for post in [posts[-1 -num] for num in range(len(posts))]: print (first_time - post.created) / (60 * 60 * 24) if first_time - post.created > 60 * 60 * 24: if post.id not in indexed: time.sleep(2)