Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import praw
  2. from termcolor import colored
  3. import sqlite3
  4.  
  5. r = praw.Reddit(client_id='<your client id>',
  6. client_secret='<your secret>',
  7. password='<your password>',
  8. user_agent='<your user agent>',
  9. username='<your username>')
  10.  
  11. print(colored('Logged in as: ' + str(r.user.me()), 'green'))
  12.  
  13.  
  14. conn = sqlite3.connect('saved.db')
  15. c = conn.cursor()
  16. c.execute('CREATE TABLE IF NOT EXISTS posts (id text)')
  17.  
  18. def alreadyExists(post):
  19. for thing in c.execute('''SELECT * FROM posts WHERE id = '{}' '''.format(post.id)):
  20. return True
  21. return False
  22.  
  23. def addPost(post):
  24. c.execute('''INSERT INTO posts VALUES ('{}') '''.format(post.id))
  25.  
  26. def generateSelftext(post):
  27. if post.selftext == '':
  28. return None
  29. else:
  30. return post.selftext
  31.  
  32.  
  33. def generateLink(post):
  34. if post.selftext == '':
  35. return post.url
  36. else:
  37. return None
  38.  
  39. def isPost(post):
  40. try:
  41. post.title
  42. return True
  43. except:
  44. return False
  45. import time
  46. def run():
  47. time.sleep(1200)
  48. 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']:
  49. try:
  50. addPost(post)
  51. print('Added post {}'.format(post.title))
  52. r.subreddit('FactorioBlueprints').submit(post.title + ' (x-post from /r/factorio)', url='https://www.reddit.com' + post.permalink, resubmit=True, send_replies=True)
  53. except:
  54. pass
  55.  
  56. while True:
  57. run()
  58. conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement