Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import re
- import base64
- reddit = praw.Reddit(client_id="",
- client_secret="",
- username="",
- password="",
- user_agent="")
- subreddit = "testingground4bots"
- def find_url(string):
- regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>" \
- r"]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
- url = re.findall(regex,string)
- return [x[0] for x in url]
- for comment in reddit.subreddit(subreddit).stream.comments(skip_existing=True):
- body = comment.body
- link = find_url(body)
- if len(link) <= 0:
- pass
- else:
- encoded_link = base64.b64encode(bytes(link[0], "utf-8"))
- comment.reply(f"Here is the link encoded in base64: {encoded_link}")
Add Comment
Please, Sign In to add comment