Skip to content

Instantly share code, notes, and snippets.

@tg12
Last active July 5, 2021 10:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tg12/6344365e85f3d27d0f95fe906ec6a0ef to your computer and use it in GitHub Desktop.
Save tg12/6344365e85f3d27d0f95fe906ec6a0ef to your computer and use it in GitHub Desktop.
Crosspost the best to the best on Reddit
import time
import praw
import sqlite3
from random import randint
from time import sleep
# FROMSUB = "cyber" # The subreddit you want to take posts from
# TOSUBS = ["cyber_security", "cyberlaws", "security", "privacy",
# "netsec", "technology", "computerforensics", "ComputerSecurity"] # The
# subreddits you want to post to
FROMSUB = "brexit" # The subreddit you want to take posts from
TOSUBS = ["ukpolitics", "unitedkingdom"] # The subreddits you want to post to
r = praw.Reddit(client_id='',
client_secret='',
password='',
user_agent="test2v_0.1",
username='')
print("Logged in as: " + str(r.user.me()))
conn = sqlite3.connect('saved.db')
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS posts (id text)')
def alreadyExists(post):
for thing in c.execute(
'''SELECT * FROM posts WHERE id = '{}' '''.format(post.id)):
return True
return False
def addPost(post):
c.execute('''INSERT INTO posts VALUES ('{}') '''.format(post.id))
def generateSelftext(post):
if post.selftext == '':
return None
else:
return post.selftext
def generateLink(post):
if post.selftext == '':
return post.url
else:
return None
def isPost(post):
try:
post.title
return True
except BaseException:
return False
def run():
for post in [post for post in r.subreddit(FROMSUB).new(
limit=20) if not alreadyExists(post) and isPost(post)]:
for each in TOSUBS:
print("[-]debug, " + str(each))
try:
print('Added post {}'.format(post.title))
r.subreddit(each).submit(
post.title +
' (x-post from /r/{})'.format(FROMSUB),
url='https://www.reddit.com' +
post.permalink,
resubmit=True,
send_replies=True)
except BaseException as e:
print(e)
sleep(randint(540, 900))
pass
addPost(post)
while True:
run()
conn.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment