Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import os
- import re
- from time import sleep
- from datetime import datetime
- os.system("") # enables ansi escape characters in terminal for windows
- #------- Settings -------#
- # Feel free to add more words. (case insensitive)
- nonowords = [''] # Had to remove them for pastebin :(
- # List to users to check. I prefer to do one at a time.
- authors=['majormajorsnowden']
- # Maximum amount of comments returned by pushshift
- amount='100'
- max_length = 9999999 # Lower this to filter comments with too many words words words
- #-----------------------#
- RED = '\033[31m'
- END = '\033[0m'
- PUSHSHIFT = 'https://api.pushshift.io/reddit/{}/search?html_decode=true&author={}&q={}&amount={}'
- REDDIT = 'https://old.reddit.com'
- COMMENT = 'comment'
- for author in authors:
- for noword in nonowords:
- #Build request
- request = PUSHSHIFT.format(COMMENT,author,noword,amount)
- #Send request and get response
- response = requests.get(request)
- #Ensure pushshift isn't rate limiting us
- while(response.status_code == 429):
- print("\n\033[33mToo many requests to pushshift api!\nWaiting 30 secs..." + END)
- sleep(30)
- response = requests.get(request)
- submissions = (response.json()).get('data')
- for submission in submissions:
- #Prepare to print list of comments
- format_string = "\033[1mUser:\033[0m {}\n\033[1mTimestamp:\033[0m {}\n\n\033[1mComment:\033\
- [0m\n{}\n\n\033[1mLink:\033[0m {}\n\n\n"
- #Format date
- date = datetime.fromtimestamp(submission["created_utc"])
- #Format body
- body = submission.get('body')
- if (len(body) > max_length):
- continue # Skip comments that are too long
- pattern = re.compile(noword, re.IGNORECASE)
- body = pattern.sub(RED + noword + END,body)
- #Format link
- link = "{}{}".format(REDDIT, submission.get("permalink"))
- print(format_string.format(submission.get("author"), date.ctime(), body, link))
- sleep(0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement