Advertisement
Guest User

RLE_Search_.py

a guest
Feb 10th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1. # Searches rocketleagueexchange for desired items, outputs to and opens html page.
  2.  
  3. from __future__ import print_function
  4. import praw
  5. import webbrowser
  6.  
  7.  
  8. def reddit_auth():
  9.     global reddit, subreddit
  10.     reddit = praw.Reddit(client_id="", client_secret="",
  11.     password='', user_agent='',
  12.     username='')
  13.     subreddit = reddit.subreddit('RocketLeagueExchange')
  14. def get_input():
  15.     global uFlair, fQuery, uLimit, uSort, uTime, uTitle
  16.     gFlair=input("Enter PC, PS4, or Xbox: ") or "PC"
  17.     uFlair="[" + gFlair + "]"
  18.     uQuery=input("Enter desired item. e.g. Hypernova:  ") or "Photon"
  19.     fQuery=(uFlair + " " + uQuery)
  20.     uLimit=input("How many results? e.g. 10:  ") or 10
  21.     uSort=input("Sort by relevance, hot, top, new, or comments?:  ") or "relevance"
  22.     uTime=input("Seach post from the last hour, day, week, month, or year?:  ") or "hour"
  23.     uTitle="Searching for post(s) containing: \"" + fQuery + "\" posted in the last " + uTime + " sorted by " + uSort
  24. def create_htm():
  25.     global  filepath, outputFile
  26.     filepath="/Scripts/Python/out.html"
  27.     outputFile=open(filepath, 'w', errors='ignore')
  28.     sTags='''<html>
  29.     <head>'''+ uTitle.upper() +'''</head>
  30.     <body><p>'''
  31.     print (sTags, file=outputFile)
  32. def close_htm():
  33.     eTags='''</p></body>
  34.     </html>'''
  35.     print (eTags, file=outputFile)
  36. def add_urllist():
  37.     print("<a href=" + submission.url + ">" + submission.title + "</a>", sep='', end='<br>', file=outputFile)
  38. def do_search():
  39.     for submission in subreddit.search(fQuery, sort=uSort, limit=int(uLimit), time_filter=uTime.lower()):
  40.         print("<a href=" + submission.url + ">" + submission.title + "</a>", sep='', end='<br>', file=outputFile)
  41. def open_htm():
  42.     webbrowser.open(filepath)
  43. def email_self(fFile): # Doesn't work, email is blank
  44.     import  smtplib
  45.     from email.mime.text import MIMEText
  46.     gmail_user=""
  47.     gmail_pwd=""
  48.     fp = open(fFile, 'r')
  49.     msg = MIMEText(fp.read(), _subtype="html")
  50.     fp.close()
  51.    
  52.     msg['Subject'] = "RLE Trades"
  53.     msg['From'] = ""
  54.     msg['TO'] = ""
  55.    
  56.     s = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  57.     s.ehlo()
  58.     s.starttls
  59.     s.login(gmail_user, gmail_pwd)
  60.     s.sendmail("to", "from", msg.as_string())
  61.     s.close
  62.    
  63. reddit_auth()
  64. get_input()
  65. create_htm()
  66. do_search()
  67. close_htm()
  68. # email_self(filepath)
  69. open_htm()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement