Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import praw
- import os
- import smtplib
- import email
- import datetime, time
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email import encoders
- from email.header import Header
- #email sender/reciever
- sender = Header('','utf-8').encode()
- recievers = ['']
- #Reddit login info
- login = ''
- password =''
- def getsub():
- #Setting up PRAW to use
- #Logging into reddit
- r = praw.Reddit(user_agent='getting top 25 of leagueoflegends by /u/legendzs')
- r.config.decode_html_entities = True
- r.login(login, password)
- #Asks user which subreddit they wish to see and how many hot posts
- sub = input('Which subreddit would you list to see?: ')
- topHowMuch= input("How many of Hot posts of /r/{} would you like to see?: ".format(sub))
- submissions = r.get_subreddit(sub).get_hot(limit=int(topHowMuch))
- #return the values of submissions and sub to be used else where
- return submissions, sub, topHowMuch
- ###Send email to different emails
- def chooseEmail():
- pass
- def gettime():
- #gets the time/date of when I send email
- timeee=time.time()
- timeee =datetime.datetime.fromtimestamp(timeee).strftime('%m-%d-%Y %I:%M %p')
- timeee = timeee[:10] + " at" +timeee[10:]
- return timeee
- def getredditurl():
- #Gets redditurl, specific thread id
- #unpacking the variables/values from getsub()
- submissions,sub, topHowMuch=getsub()
- link=''
- for top10format in submissions:
- link += ("""
- <li>
- <a href="www.reddit.com/r/leagueoflegends/{0}/">
- {0}
- </a>
- </li>
- """).format(top10format.id)
- return link, sub,topHowMuch
- def htmlmessage():
- #Extracting variables that I need
- timeee= gettime()
- link, sub, topHowMuch=getredditurl()
- ###### use a variable that formats the <li> <a href> links in
- html ="""
- <html>
- <body>
- <h2>The Top {} hottest posts on /r/{} on {}</h2>
- <br>
- <ol>
- {}
- </ol>
- </body>
- </html>
- """.format(topHowMuch, sub, timeee, link)
- return html
- def completeEmail():
- html=htmlmessage()
- #loging into email
- username = ""
- password1 = ""
- email = smtplib.SMTP('smtp.gmail.com:587')
- email.starttls()
- email.login(username, password1)
- msg = MIMEMultipart('alternative')
- msg['To']= recievers
- msg['From'] = sender
- msg['Subject']= "Reddit posts"
- part1 = MIMEText(html, 'html')
- msg.attach(part1)
- return msg, email
- def emailsend():
- msg, email=completeEmail()
- try:
- email.sendmail(sender,recievers,msg)
- except:
- print("Didn't send - unknown error")
- finally:
- email.quit()
- emailsend()
Add Comment
Please, Sign In to add comment