Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import configparser
- import pandas as pd
- import uuid
- config_path = '<configfilenamegoeshere>'
- config = configparser.ConfigParser()
- config.read(config_path)
- # I'm often reusing authentication part from config file above for convenience but you can define parameters directly here
- reddit = praw.Reddit(client_id=config['reddit']['client_id'],
- client_secret=config['reddit']['client_secret'],
- user_agent=config['reddit']['user_agent'],
- password=config['reddit']['password'],
- username=config['reddit']['username'])
- comments = pd.read_csv('comment_headers.csv')
- # optional part - I wanted to delete comments from specific sub only
- comments = comments[(comments.subreddit == '<subredditnamegoeshere>')]
- comments = comments.reset_index()
- for index, row in comments.iterrows():
- print(f'{index+1} / {len(comments)}: {row.id}')
- try:
- comment = reddit.comment(row.id)
- # optional part - replacing comment contents with noise before deleting, makes it much slower but you can do it just in case reddit stores it anyway (supposedly they don't store history so...)
- comment.edit(body = uuid.uuid4())
- comment.delete()
- except Exception as zonk:
- print(f'failed: {zonk}')
- print('done')
Advertisement
Add Comment
Please, Sign In to add comment