Created
November 8, 2023 14:45
-
-
Save RoseSecurity/287b87dc44ce604884f837f69425debb to your computer and use it in GitHub Desktop.
A simple Python utility that harnesses Reddit's API to create custom feeds for your Streamlit application.
This file contains 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
#!/usr/bin/env python3 | |
import streamlit as st | |
import praw | |
# Instantiate bot | |
reddit = praw.Reddit(client_id=st.secrets["CLIENTID"], | |
client_secret=st.secrets["CLIENTSECRET"], | |
user_agent='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', | |
username=st.secrets["USERNAME"], | |
password=st.secrets["PASSWORD"]) | |
# Function to display subreddit posts | |
def display_subreddit_posts(subreddit_name): | |
subreddit = reddit.subreddit(subreddit_name) | |
for submission in subreddit.hot(limit=10): | |
st.header(submission.title) | |
st.write(submission.selftext) | |
st.divider() | |
# Title | |
st.title("RoseSecurity's Reddit Feed") | |
# Subreddits | |
my_subreddits = ["hacking", "infosec", "redteamsec", | |
"cybersecurity", "netsec", "hackernews", "devops", "terraform", "ansible", "aws", "github", "homelab", "homenetworking", | |
"kubernetes", "networking", "proxmox", "sysadmin", "vscode", "sre", "azure", "docker", "linux", "bash", "ubuntu", "vim", "debian", | |
"freebsd", "fedora", "golang", "kde", "gnome", "opensource"] | |
# Tabs | |
my_tabs = st.sidebar.selectbox("Select a subreddit:", my_subreddits) | |
# Display subreddit posts when a tab is selected | |
display_subreddit_posts(my_tabs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment