Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import praw
  2. import time
  3. import itertools
  4. import smtplib
  5. from email.mime.text import MIMEText
  6.  
  7. SMTP_SERVER = "smtp.mail.yahoo.com"
  8. SMTP_PORT = 587
  9. SMTP_USERNAME = "email"
  10. SMTP_PASSWORD = "pass"
  11. EMAIL_FROM = "email"
  12. EMAIL_TO = "3039192150@vtext.com"
  13. EMAIL_SUBJECT = ""
  14. msg_to_send = ""
  15. batch_count = 0
  16.  
  17. def redditParse():
  18.     user_agent = ("PyEng Test 0.0.1")
  19.     r = praw.Reddit(user_agent = user_agent)
  20.     tick = 1800
  21.  
  22.     subreddit = r.get_subreddit("pcmasterrace")
  23.     title = ""
  24.     seen = set()
  25.  
  26.     for i in itertools.count():
  27.         for submission in subreddit.get_new(limit = 100):
  28.             title = submission.title
  29.             if"giveaway" in title.lower() and (title not in seen):
  30.                 #print("\nPost:\t", title)
  31.                 #print("Link:\t", submission.url)
  32.                 seen.add(title)
  33.                 temp_msg_builder(title, submission.url)
  34.  
  35.         #sleep for a min, then try again       
  36.         time.sleep(tick)
  37.  
  38. def temp_msg_builder(title, url):
  39.     temp_msg = """
  40. Post: %s
  41.  
  42. Link: %s
  43. """ % (title, url)
  44.     print("\n\n\n\n\nSENDING: \n", temp_msg)
  45.     send_email(temp_msg)
  46.  
  47. def send_email(co_msg):
  48.     try:
  49.         msg = MIMEText(co_msg)
  50.         msg['Subject'] = EMAIL_SUBJECT
  51.         msg['From'] = EMAIL_FROM
  52.         msg['To'] = EMAIL_TO
  53.         debuglevel = True
  54.         mail = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
  55.         mail.set_debuglevel(debuglevel)
  56.         mail.starttls()
  57.         mail.login(SMTP_USERNAME, SMTP_PASSWORD+"77")
  58.         mail.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())
  59.         mail.quit()
  60.         print("\n\n\n\nSent!\n\n\n\n")
  61.     except:
  62.         print("Couldn't send")
  63.  
  64.  
  65. redditParse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement