from __future__ import print_function, division
import io_utils
import scraper
import praw
import pandas as pd
from config import Config

options = Config()
reddit = praw.Reddit(user_agent = options.user_agent)

new_posts = reddit.get_subreddit(options.network_hub).get_new(limit=options.post_limit)

def get_new_authors(post_generator, author_list=None):
    """Basic syntax to gather a list of post and comment authors
    gathered from new posts on the target subreddit

    To Do:
    - More structured data processing
    - Maybe flatten the comment tree?
    """

    if not author_list:
        author_list = []

    for post in post_generator:
        author_list.append(post.author.name)
        for comment in post.comments:
            author_list.append(comment.author.name)

    author_df = pd.DataFrame({'user_name': author_list, 'highest_post_id': ""})
    author_df = author_df.drop_duplicates('user_name')
    print('%d new authors found!' % (len(author_df.user_name)))
    return author_df

def get_user_comments(username):
    # I'm fairly positive this doesn't actually work
    user_comments = user.get_submitted(limit=10)

@@ -41,16 +41,28 @@
 ivision%0A
+import time%0A
 import i
@@ -69,16 +69,16 @@
 o_utils%0A
-
 import s
@@ -326,16 +326,23 @@
 authors(
+reddit_
 post_gen
@@ -644,24 +644,31 @@
 for post in 
+reddit_
 post_generat
@@ -1036,135 +1036,1710 @@
 def 
-get_user_comments(username):%0A    # I'm fairly positive this doesn't actually work%0A    user_comments = user.get_submitted(limit=10)
+comment_parser(reddit_comment_object):%0A%0A    post_timestamp = reddit_comment_object.created_utc%0A    score = reddit_comment_object.score%0A    ups = reddit_comment_object.ups%0A    downs = reddit_comment_object.downs%0A    post_body = reddit_comment_object.body%0A    link_title = reddit_comment_object.link_title%0A    link_id = reddit_comment_object.link_id%0A    link_author = reddit_comment_object.link_author%0A    subreddit = reddit_comment_object.subreddit.display_name%0A%0A    return post_timestamp, score, ups, downs, post_body, link_title, link_id, link_author, subreddit%0A%0A%0Adef get_user_comments(reddit_user_object, comment_dataframe=None):%0A%0A    user_name = reddit_user_object.name%0A    user_comments = reddit_user_object.get_comments(limit=1000) # Due to reddit's caching, 1000 is the absolute max%0A%0A    if not comment_dataframe:%0A        comment_dataframe = pd.DataFrame(columns=%5B%0A        'user_name',%0A        'post_timestamp',%0A        'score',%0A        'ups',%0A        'downs',%0A        'post_body',%0A        'link_title',%0A        'link_id',%0A        'link_author',%0A        'subreddit',%0A        'timestamp'%0A        %5D)%0A%0A    for comment in user_comments:%0A        post_timestamp, score, ups, downs, post_body, link_title, link_id, link_author, subreddit = comment_parser(comment)%0A        comment_dataframe = comment_dataframe.append(%7B%0A        'user_name': user_name,%0A        'post_timestamp': post_timestamp,%0A        'score': score,%0A        'ups': ups,%0A        'downs': downs,%0A        'post_body': post_body,%0A        'link_title': link_title,%0A        'link_id': link_id,%0A        'link_author': link_author,%0A        'subreddit': subreddit,%0A        'timestamp': time.time()%7D, ignore_index=True)%0A%0A    return comment_dataframe
 %0A

comment parsing