Advertisement
Guest User

bot.py

a guest
Aug 9th, 2019
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. import os
  2. import psycopg2
  3. import time
  4. import praw
  5.  
  6. while True:
  7.     reddit = praw.Reddit(username = os.environ['username'],
  8.                         password = os.environ['password'],
  9.                         client_id = os.environ['client_id'],
  10.                         client_secret = os.environ['client_secret'],
  11.                         user_agent = os.environ['user_agent'])
  12.  
  13.     subreddit = reddit.subreddit("Flume")
  14.  
  15.     submission = reddit.submission(url = os.environ['url'])
  16.  
  17.     submission.comments.replace_more(limit=None)
  18.  
  19.     conn = psycopg2.connect(os.environ['DATABASE_URL'], sslmode='require')
  20.  
  21.     cur = conn.cursor()
  22.  
  23.     for comment in submission.comments:
  24.         cur.execute("SELECT commentID FROM Comment WHERE commentID = %s;", (str(comment.id),))
  25.         result = cur.fetchall()
  26.         if (len(result) == 0) :
  27.             user = comment.author
  28.             print("New comment, sending link to: " + user.name)
  29.             cur.execute("INSERT INTO Comment VALUES (%s)", (str(comment.id),))
  30.             reddit.redditor(user.name).message("Flume Stream Link", os.environ['dl_link']
  31.                 + "\n\nLet me know if this link dies as well. Enjoy!"
  32.                 + "\n\n To prevent this link from being taken down easily, please DON'T post it on other subreddits like r/xTrill, I greatly appreciate your help!")
  33.             comment.reply("sent")
  34.  
  35.     conn.commit()
  36.  
  37.     cur.close()
  38.     conn.close()
  39.     time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement