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()
Beispiel #2
0
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')}
import time
import urllib2

tobaccoName = ""


class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        global tobaccoName
        if (tag == "meta"):
            if 'itemprop' in dict(attrs):
                if dict(attrs)['itemprop'] == "itemreviewed":
                    tobaccoName = dict(attrs)['content']


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