Guest User

Untitled

a guest
Oct 20th, 2020
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import praw
  2. import re
  3. import base64
  4.  
  5. reddit = praw.Reddit(client_id="",
  6.                      client_secret="",
  7.                      username="",
  8.                      password="",
  9.                      user_agent="")
  10.  
  11. subreddit = "testingground4bots"
  12.  
  13. def find_url(string):
  14.     regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>" \
  15.             r"]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
  16.     url = re.findall(regex,string)
  17.     return [x[0] for x in url]
  18.  
  19.  
  20. for comment in reddit.subreddit(subreddit).stream.comments(skip_existing=True):
  21.     body = comment.body
  22.     link = find_url(body)
  23.     if len(link) <= 0:
  24.         pass
  25.     else:
  26.         encoded_link = base64.b64encode(bytes(link[0], "utf-8"))
  27.         comment.reply(f"Here is the link encoded in base64: {encoded_link}")
  28.  
  29.  
Add Comment
Please, Sign In to add comment