Advertisement
Guest User

Untitled

a guest
Mar 14th, 2022
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. import requests
  2. import os
  3. import re
  4. from time import sleep
  5. from datetime import datetime
  6.  
  7. os.system("")  # enables ansi escape characters in terminal for windows
  8.  
  9. #------- Settings -------#
  10.  
  11. # Feel free to add more words. (case insensitive)
  12. nonowords = [''] # Had to remove them for pastebin :(
  13.  
  14. # List to users to check. I prefer to do one at a time.
  15. authors=['majormajorsnowden']
  16.  
  17. # Maximum amount of comments returned by pushshift
  18. amount='100'
  19. max_length = 9999999  # Lower this to filter comments with too many words words words
  20. #-----------------------#
  21.  
  22. RED = '\033[31m'
  23. END = '\033[0m'
  24. PUSHSHIFT = 'https://api.pushshift.io/reddit/{}/search?html_decode=true&author={}&q={}&amount={}'
  25. REDDIT = 'https://old.reddit.com'
  26. COMMENT = 'comment'
  27.  
  28.  
  29.  
  30. for author in authors:
  31.         for noword in nonowords:
  32.                 #Build request
  33.                 request = PUSHSHIFT.format(COMMENT,author,noword,amount)
  34.                 #Send request and get response
  35.                 response = requests.get(request)
  36.  
  37.                 #Ensure pushshift isn't rate limiting us
  38.                 while(response.status_code == 429):
  39.                         print("\n\033[33mToo many requests to pushshift api!\nWaiting 30 secs..." + END)
  40.                         sleep(30)
  41.                         response = requests.get(request)
  42.  
  43.                 submissions = (response.json()).get('data')
  44.  
  45.                 for submission in submissions:
  46.                         #Prepare to print list of comments
  47.                         format_string = "\033[1mUser:\033[0m {}\n\033[1mTimestamp:\033[0m {}\n\n\033[1mComment:\033\
  48.                                        [0m\n{}\n\n\033[1mLink:\033[0m {}\n\n\n"
  49.  
  50.                         #Format date
  51.                         date = datetime.fromtimestamp(submission["created_utc"])
  52.                         #Format body
  53.                         body = submission.get('body')
  54.  
  55.                         if (len(body) > max_length):
  56.                                 continue # Skip comments that are too long
  57.  
  58.                         pattern = re.compile(noword, re.IGNORECASE)
  59.                         body = pattern.sub(RED + noword + END,body)
  60.  
  61.  
  62.                         #Format link
  63.                         link = "{}{}".format(REDDIT, submission.get("permalink"))
  64.  
  65.                         print(format_string.format(submission.get("author"), date.ctime(), body, link))
  66.                 sleep(0.2)
  67.  
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement