コード例 #1
0
def should_add(worksheet: pyg.Worksheet, comment: praw.reddit.models.Comment):
    """
    Whether or not a comment passes the criteria for adding to the Google Sheet and replying
    :param worksheet: worksheet containing grey points
    :param comment: comment by Grey
    :return: Whether comment passes
    """
    # not in sheet
    worksheet_df = worksheet.get_as_df()
    if comment.id in worksheet_df['Comment ID'].to_list():
        return False

    # grey deleted his comment or it was removed
    if comment.removal_reason is not None:
        return False

    # parent is deleted
    if comment.parent().author is None:
        return False

    # doesn't contain point_trigger
    if not contains_point_trigger(comment.body):
        return False

    return True
コード例 #2
0
def add_comment_to_sheet(comment: praw.reddit.models.Comment,
                         worksheet: pyg.Worksheet):
    worksheet_df = worksheet.get_as_df()
    formatted_utc = datetime.utcfromtimestamp(comment.created_utc)
    new_entry = {
        'Point ID': worksheet_df['Point ID'].max() + 1,
        'Username': rf'/u/{comment.parent().author}',
        'Comment Link':
        rf'https://old.reddit.com/comments/{comment.link_id[3:]}/_/{comment.id}/?context=3',
        'Subreddit': rf"/r/{comment.subreddit}",
        'Date': formatted_utc.strftime('%Y-%m-%d  %H:%M:%S'),
        'Comment ID': comment.id
    }

    worksheet_df = pd.concat(
        [worksheet_df, pd.DataFrame(new_entry, index=[1])])
    worksheet.set_dataframe(worksheet_df, start='A1')