Skip to content

Instantly share code, notes, and snippets.

@gavin19
gavin19 / avis.py
Last active March 8, 2020 11:25
Scrape avatars from the subreddit mods page
import requests
from bs4 import BeautifulSoup as bs
from time import sleep
HEADERS = {"user-agent": "win64:avatar-scraper:/u/gavin19"}
USER_CLS = "_2Q3rLIRb_ij54AEsabVm9L"
PAGE_CLS = "_2QinjfjfDTG6Df4_Tb_eRN"
MOD_PAGE = "https://new.reddit.com/r/pics/about/moderators/"
tmp_page = MOD_PAGE
avis = {}
import praw
userAgent = 'xxx'
cID = 'xxx'
cSC= 'xxx'
userN = 'xxx'
userP ='xxx'
numFound = 0
reddit = praw.Reddit(user_agent=userAgent,
@gavin19
gavin19 / pics_dl.py
Created July 1, 2019 13:46
Download images from reddit by keyword/subreddit/time/limit
import re, praw, requests
from time import sleep
def my_robot(query, sub='all', time='all', limit=25):
r = praw.Reddit(...)
# Get `limit` no. of posts based on `sub`, `query` and `time`
posts = [p for p in r.subreddit(sub).search(query, time, limit=limit)]
# Compile query pattern for regex search
@gavin19
gavin19 / echo_bot.py
Created June 24, 2019 14:16
Strip text content from Echo posts and submit comment
#!/usr/bin/python3
import os
import sys
import praw
import requests
import simplejson
from bs4 import BeautifulSoup as BSp
import html2text
from time import sleep
@gavin19
gavin19 / reddit_cap_comments.py
Last active July 16, 2023 15:07
Screenshot top-level reddit comments
from selenium.webdriver import Firefox, FirefoxOptions
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
import praw
from time import sleep
r = praw.Reddit(...)
opts = FirefoxOptions()
opts.add_argument("--headless")
import praw
CMT_PHRASE = "some phrase"
PARENT_PHRASE = "another phrase"
r = praw.Reddit(...)
cmt_stream = r.subreddit("pics").stream.comments(skip_existing=True)
def check phrase(cmt, parent):
@gavin19
gavin19 / prawtime.py
Last active February 14, 2021 22:03
Get posts going back given duration (d/h/m)
import praw
import time
from datetime import datetime
from operator import attrgetter
def get_posts(subreddit):
r = praw.Reddit(...)
sub = r.subreddit(subreddit)
@gavin19
gavin19 / upvoted_counter.py
Created January 21, 2019 13:58
Print list of upvoted links on reddit by count per subreddit, then subreddit name.
import praw
def main():
r = praw.Reddit(user_agent='/u/someuser upvoted counter',
client_id='CLIENT_ID', client_secret='CLIENT_SECRET',
username='USERNAME', password='PASSWORD')
liked = r.user.me().upvoted(limit=None)
likes = {}
for l in liked:
import praw
SUB = "somesub" # subreddit to watch for comments
TO_SKIP = ['HappySilveon', 'AutoModerator'] # list of users to ignore
SUBJECT = "Some subject" # required subject for the PM
REPLY = "PM content here." # The content of the PM we'll respond with
def main():
reddit = praw.Reddit(user_agent='/u/HappySilveon reply script',
import os
import re
import praw
import time
SKIP = ['tacobellscannon'] # users to skip replies to
WORDS = ['aword', 'word2'] # words to match
REPLY = "You said, '{0}'. Thanks." # template for replies
LAUNCHED = time.time()