Created
April 14, 2022 17:30
-
-
Save TheNightmanCodeth/f5bb9b6b4e621718764ef3c6c9436640 to your computer and use it in GitHub Desktop.
A Reddit bot that replies to a post with a steam link for items in the body of a self-text inside of double brackets (ie. [[Portal 2]])
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import praw | |
import re | |
import requests | |
search_api = 'https://steamcommunity.com/actions/SearchApps/' | |
steam_link = 'https://store.steampowered.com/app/' | |
## Populate with your own client_id, etc. from: | |
## https://www.reddit.com/prefs/apps | |
reddit = praw.Reddit( | |
client_id="", # String underneath the bots name on the reddit `apps` page | |
client_secret="", # Find on the bots page on reddit.com/prefs/apps | |
user_agent="", # Something like: "python:com.example.botname:v1.0.0 (by /u/yourusername)" | |
password="", # The password for your bots' account | |
username="" # The usernmae for your bots' account | |
) | |
# V Add the subreddit you want the bot to run on here | |
for post in reddit.subreddit(" ").stream.submissions(): | |
body = post.selftext.replace('\\', '') | |
reply = "" | |
if (body != ""): | |
hits = re.findall('\[\[(.*?)\]\]', body) | |
if hits is not None: | |
print(hits) | |
for hit in hits: | |
print(f'Found: {hit}') | |
search_term = hit.replace(" ", "%20") | |
url = search_api + search_term | |
req = requests.get(url) | |
appid = req.json()[0]['appid'] | |
name = req.json()[0]['name'] | |
link = steam_link + appid | |
# This is the string that will be sent as a reply. | |
# You can change this. Use markdown, etc. | |
reply += f'#{name} \n {link} \n' | |
print(f'Reply: {reply}') | |
post.reply(reply) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment