예제 #1
0
def get_fresh_comment_with_symbols(submission):
    comments = submission.comments
    print("Processing %d comments in this submission" % len(comments))
    for top_level_comment in comments:

        if isinstance(top_level_comment, MoreComments):
            continue

        is_replied = check_if_replied(top_level_comment)

        if is_replied is True:
            continue

        symbols = cparser.parse_comment(top_level_comment)
        if len(symbols) > 0:
            print("Fresh comment found : %s" % top_level_comment.id)
            return top_level_comment
    return None
예제 #2
0
def handle_submission(db, submission):
    poster = submission.author.name
    sub = submission.subreddit.display_name
    body = html.unescape(submission.selftext)
    url = html.unescape(submission.url)
    text = body + "\n" + url

    if parser.contains_reference(text):
        logger.info('Found potential xkcd reference(s) in submission %s',
                    submission.fullname)
        references = parser.parse_comment(db, text)
        handle_references(db, references, 'Submission', poster, sub,
                          submission.fullname, None, None)
        do_reply(submission, db, poster, references)

    comments = submission.comments
    comments.replace_more()
    for comment in submission.comments:
        handle_comment(db, comment, text)
예제 #3
0
    def parse_page(self, response):
        """Searches and scrapes valid Bitcoins from this Page.
        """
        # Search each comment for a valid Bitcoin address
        for comment in itertools.chain(
                response.css('.windowbg').extract(),
                response.css('windowbg2').extract()):
            valid_addresses = collect_bitcoins(str.encode(comment))
            if len(valid_addresses) > 0:
                logging.debug("Page {}, yielding Bitcoins".format(
                    response.url))
                p = parse_comment(comment)

                comment = {
                    "username": p["username"],
                    "bitcoin_addresses": valid_addresses,
                    "profile_url": p["profile_url"],
                    "date": p["date"],
                    "comment": p["comment"],
                    "comment_url": response.url
                }
                yield comment
예제 #4
0
def handle_comment(db, comment, parent_text):
    if isinstance(comment, MoreComments):
        return

    poster = '[deleted]'
    if comment.author is not None:
        poster = comment.author.name
    body = html.unescape(comment.body)
    sub = comment.subreddit.display_name
    parent_id = comment.parent_id

    if parser.contains_reference(body):
        logger.info('Found potential xkcd reference in comment %s',
                    comment.fullname)
        references = parser.parse_comment(db, body)
        handle_references(db, references, 'Comment', poster, sub,
                          comment.fullname, parent_id, parent_text)
        do_reply(comment, db, poster, references)

    replies = comment.replies
    replies.replace_more()
    for reply in replies:
        handle_comment(db, reply, comment.body)
예제 #5
0
    for submission in submissions:
        title = submission.title
        if any(word in title.lower() for word in exclude_submissions):
            print("Skipping submission : %s " % title)
            continue
        print("Processing submission : %s" % title)
        fresh_comment = rc.get_fresh_comment_with_symbols(submission)
        if fresh_comment is None:
            continue
        is_fresh_comment_found = True
        print("Found fresh comment in submission : %s with comment id : %s " %
              (title, fresh_comment.id))
        break

    if fresh_comment is not None:
        symbols = cparser.parse_comment(fresh_comment)
        symbols = list(sorted(set(symbols)))
        #print(symbols)
        if len(symbols) < 8:
            bot_comment = cbuilder.build_bot_comment(symbols)
            print(
                "\nBot generated comment in response to comment id %s : \n%s" %
                (fresh_comment.id, bot_comment))
            response_comment = fresh_comment.reply(bot_comment)
            #response_comment = comment # uncomment for testing without the api call
        else:
            print("Skipping comment with 8 or more symbols : %s" %
                  fresh_comment.id)
    else:
        print("No fresh comment found")