Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- from termcolor import colored
- import sqlite3
- r = praw.Reddit(client_id='<your client id>',
- client_secret='<your secret>',
- password='<your password>',
- user_agent='<your user agent>',
- username='<your username>')
- print(colored('Logged in as: ' + str(r.user.me()), 'green'))
- 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:
- return False
- import time
- def run():
- time.sleep(1200)
- for post in [post for post in r.subreddit('factorio').new(limit=20) if not alreadyExists(post) and isPost(post) and str(post.link_flair_text).lower() == 'design / blueprint']:
- try:
- addPost(post)
- print('Added post {}'.format(post.title))
- r.subreddit('FactorioBlueprints').submit(post.title + ' (x-post from /r/factorio)', url='https://www.reddit.com' + post.permalink, resubmit=True, send_replies=True)
- except:
- pass
- while True:
- run()
- conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement