Guest User

Untitled

a guest
Jun 4th, 2023
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. import praw
  2. import configparser
  3. import pandas as pd
  4. import uuid
  5.  
  6. config_path = '<configfilenamegoeshere>'
  7. config = configparser.ConfigParser()
  8. config.read(config_path)
  9.  
  10. # I'm often reusing authentication part from config file above for convenience but you can define parameters directly here
  11.  
  12. reddit = praw.Reddit(client_id=config['reddit']['client_id'],
  13. client_secret=config['reddit']['client_secret'],
  14. user_agent=config['reddit']['user_agent'],
  15. password=config['reddit']['password'],
  16. username=config['reddit']['username'])
  17.  
  18. comments = pd.read_csv('comment_headers.csv')
  19. # optional part - I wanted to delete comments from specific sub only
  20. comments = comments[(comments.subreddit == '<subredditnamegoeshere>')]
  21. comments = comments.reset_index()
  22.  
  23. for index, row in comments.iterrows():
  24. print(f'{index+1} / {len(comments)}: {row.id}')
  25. try:
  26. comment = reddit.comment(row.id)
  27. # 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...)
  28. comment.edit(body = uuid.uuid4())
  29. comment.delete()
  30. except Exception as zonk:
  31. print(f'failed: {zonk}')
  32. print('done')
  33.  
Advertisement
Add Comment
Please, Sign In to add comment