Beispiel #1
0
# Subscribe to spacedicks!
subs = reddit.get('/reddits')
# 'subs' is reddit's huge list of subreddits
subbed = False
while not subbed:
	# Iterate over all subreddits
	for sub in subs:
		if sub.display_name == 'spacedicks':
			reddit.subscribe(sub)
			print('subscribed to spacedicks')
			subbed = True
			break
	if not subbed and reddit.has_next():
		print('loading next page of subreddits...')
		subs = reddit.get_next()
	else:
		break


# Unsub from spacedicks!
subs = reddit.get('/reddits/mine')
# 'subs' is the user's list of subscribed subreddits
for sub in subs:
	if sub.display_name == 'spacedicks':
		reddit.subscribe(sub, unsub=True)
		print('unsubscribed to spacedicks')
		break


# Test marking NSFW, approving/removing/reporting/distinguishing/spam
Beispiel #2
0
	Web: Web requests utility library, used by ReddiWrap

(c) Antonio Herraiz August/2013
"""
from ReddiWrap import ReddiWrap

reddit = ReddiWrap(user_agent='ReddiWrap')
import time # For sleep(), to avoid API rate limit
count = 0
pics = []
comments = reddit.get_user_comments('Only_Says_Nice_Tits')
if comments != None:
	while True:
		for comment in comments:
			# reddit.last_url will be like: http://reddit.com/r/funny/comments/1jkgf3/cbfmmzu.json
			post = reddit.get('/r/%s/comments/%s/%s' % (comment.subreddit, comment.link_id[3:], comment.id))
			url = post[0].url
			if 'imgur' in url and 'i.imgur' not in url:
				# TODO: http://imgur.com/ipv9GiY ==> http://i.imgur.com/ipv9GiY.xxx
				print('Transforming imgur URL')
			pics.append(url)
			print('Pic URL: %s' % (url))
			count += 1
		if count >= 100 or not reddit.has_next(): break
		time.sleep(2) # One request every 2 seconds.
		comments = reddit.get_next()
else:
	print('I can\'t retrieve stuff from reddit.com')
# TODO: do something with 'pics'

# EOF
Beispiel #3
0
	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:
			print('unable to log in: %d' % login)
			print('remember to change USERNAME and PASSWORD')
			exit(1)
		reddit.save_cookies('cookies.txt')
	print('logged in as %s' % reddit.user)

	#Get posts in subreddit SUB
	posts = reddit.get('/r/%s' % SUB)
	print('getting posts in subreddit /r/%s' % SUB)
	while reddit.has_next():
		posts += reddit.get_next()
		time.sleep(2)	
	print('number of posts in /r/%s: %d' % (SUB, len(posts)))

	#Set up XML
	srn = ET.Element('searchresult')
	subredditnode = ET.SubElement(srn, SUB)

	#Set up for JSON dump
	subreddit = {}

	#Get data for each post
	post_count = -1
	month = timedelta(days=31)
	curr_date = date.today()
	for i in range(len(posts)):
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...'
Beispiel #5
0
        # # # # # # # # Finding Subreddit
        print "Finding Subreddit ..."
        subreddit = ""
        flag = False
        # if we find the subreddit, this flag is going to be Ture
        while True:
            subreddits = reddit.get('/reddits')
            for subred in subreddits:
                if subred.display_name == MOD_SUB.lower():
                    subreddit = subred
                    flag = True
                    break
            if (not reddit.has_next()) or flag:
                break
            time.sleep(2)
            subreddits = reddit.get_next()

        # # # # # # # # saving subreddit in subreddit table
        print "Saving Subreddit ... "
        over18 = 0
        if subreddit.over18:
            over18 = 1
        if not myLib.exsits_row(subreddit.id, "Subreddit"):
            myLib.insert_row([
                subreddit.id, subreddit.name, subreddit.display_name,
                subreddit.title, subreddit.url, subreddit.description,
                subreddit.created, over18,
                int(subreddit.subscribers), subreddit.header_title
            ], "Subreddit")

        # # # # # # # # Saving Posts
Beispiel #6
0
# Subscribe to spacedicks!
subs = reddit.get('/reddits')
# 'subs' is reddit's huge list of subreddits
subbed = False
while not subbed:
    # Iterate over all subreddits
    for sub in subs:
        if sub.display_name == 'spacedicks':
            reddit.subscribe(sub)
            print('subscribed to spacedicks')
            subbed = True
            break
    if not subbed and reddit.has_next():
        print('loading next page of subreddits...')
        subs = reddit.get_next()
    else:
        break

# Unsub from spacedicks!
subs = reddit.get('/reddits/mine')
# 'subs' is the user's list of subscribed subreddits
for sub in subs:
    if sub.display_name == 'spacedicks':
        reddit.subscribe(sub, unsub=True)
        print('unsubscribed to spacedicks')
        break

# Test marking NSFW, approving/removing/reporting/distinguishing/spam
# Assumes first post in user's history is in subreddit user is moderator of
posts = reddit.get('/user/%s/submitted' % (reddit.user))