Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- import time
- import sys
- import os
- import smtplib
- print "\nChecking student center for new grades:"
- sys.stdout.write('.')
- sys.stdout.flush()
- driver = webdriver.PhantomJS()
- try:
- f = [i.strip() for i in open('login_info.txt').readlines()]
- username = f[0]
- password = f[1]
- prevCredits = f[2]
- except Exception as e:
- print "\n\n*** Your login_info.txt isn't setup correctly! ***"
- print "You need a login_info.txt in this folder in the following format:\n"
- print "netid"
- print "password"
- print "credits you know are graded already"
- print "\ne.g.\n"
- print "abc123\np@ssword123\n4.000"
- exit()
- sys.stdout.write('.')
- sys.stdout.flush()
- NETWORK_SLOWNESS = 1
- driver.get("https://studentcenter.cornell.edu")
- usernameinput = driver.find_element_by_name("netid")
- passwdinput = driver.find_element_by_name("password")
- usernameinput.send_keys(username)
- passwdinput.send_keys(password)
- driver.find_element_by_name("Submit").click()
- sys.stdout.write('.')
- sys.stdout.flush()
- time.sleep(NETWORK_SLOWNESS)
- time.sleep(NETWORK_SLOWNESS)
- if driver.title == "Cornell University Web Login":
- print "\n\n*** Looks like your username and password are wrong. Double check and try again. ***"
- exit()
- sys.stdout.write('.')
- sys.stdout.flush()
- found = False
- while (not found):
- # print "Finding iframe"
- sys.stdout.flush()
- time.sleep(NETWORK_SLOWNESS)
- try:
- iframe = driver.find_element_by_id("ptifrmtgtframe")
- driver.switch_to.frame(iframe)
- found = True
- except Exception as e:
- # print e
- pass
- sys.stdout.write('.')
- sys.stdout.flush()
- found = False
- dropdown = None
- while (not found):
- # print "Finding dropdown"
- sys.stdout.flush()
- time.sleep(NETWORK_SLOWNESS)
- try:
- dropdown = driver.find_element_by_id("DERIVED_SSS_SCL_SSS_MORE_ACADEMICS")
- found = True
- except Exception as e:
- # print e
- pass
- sys.stdout.write('.')
- sys.stdout.flush()
- # print "Selecting Grades"
- sys.stdout.flush()
- dropdown.click()
- dropdown.send_keys("G")
- dropdown.send_keys(Keys.RETURN)
- # dropdown.send_keys(Keys.TAB)
- # driver.switch_to.active_element.send_keys(Keys.RETURN)
- time.sleep(NETWORK_SLOWNESS)
- driver.find_element_by_id("DERIVED_SSS_SCL_SSS_GO_1").click()
- sys.stdout.write('.')
- sys.stdout.flush()
- driver.switch_to.default_content()
- found = False
- while (not found):
- # print "Finding iframe"
- sys.stdout.flush()
- time.sleep(NETWORK_SLOWNESS)
- try:
- iframe = driver.find_element_by_id("ptifrmtgtframe")
- driver.switch_to.frame(iframe)
- found = True
- except Exception as e:
- # print e
- pass
- sys.stdout.write('.')
- sys.stdout.flush()
- # print "Changing Term"
- sys.stdout.flush()
- time.sleep(NETWORK_SLOWNESS*2)
- driver.find_element_by_id("DERIVED_SSS_SCT_SSS_TERM_LINK").click()
- driver.switch_to.default_content()
- found = False
- while (not found):
- # print "Finding iframe"
- sys.stdout.flush()
- time.sleep(NETWORK_SLOWNESS)
- try:
- iframe = driver.find_element_by_id("ptifrmtgtframe")
- driver.switch_to.frame(iframe)
- found = True
- except Exception as e:
- # print e
- pass
- sys.stdout.write('.')
- sys.stdout.flush()
- # print "Choosing last semester"
- sys.stdout.flush()
- driver.find_element_by_id("SSR_DUMMY_RECV1$sels$1$$0").click()
- driver.find_element_by_id("DERIVED_SSS_SCT_SSR_PB_GO").click()
- driver.switch_to.default_content()
- found = False
- while (not found):
- # print "Finding iframe"
- sys.stdout.flush()
- time.sleep(NETWORK_SLOWNESS)
- try:
- iframe = driver.find_element_by_id("ptifrmtgtframe")
- driver.switch_to.frame(iframe)
- found = True
- except Exception as e:
- # print e
- pass
- print ".\n"
- sys.stdout.flush()
- currCred = driver.find_element_by_id("STATS_ENRL$2").get_attribute('innerHTML')
- table = driver.find_element_by_id("TERM_CLASSES$scroll$0").get_attribute('innerHTML')
- if (float(currCred) == float(prevCredits)):
- print "No new grades, carry on with your life."
- else:
- F = open("login_info.txt","w")
- F.write(username+"\n")
- F.write(password+"\n")
- F.write(currCred+"\n")
- print "New grades are posted! I've updated the login_info.txt so you won't be notified again."
- print "Current graded credits: "+str(currCred)
- # gmail_user = username+'@cornell.edu'
- # gmail_password = password
- # sent_from = gmail_user
- # to = [gmail_user]
- # subject = 'New Grades'
- body = "<html>\n<head>\n</head>\n<body>\n"+table+"\n</body>\n</html>"
- # email_text = """\
- # From: %s
- # To: %s
- # Subject: %s
- # %s
- # """ % (sent_from, ", ".join(to), subject, body)
- # try:
- # server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
- # server.ehlo()
- # server.login(gmail_user, gmail_password)
- # server.sendmail(sent_from, to, email_text)
- # server.close()
- # print 'Email sent with your grades attached!'
- # except Exception as e:
- # print "The email didn't send, check StudentCenter."
- # raise e
- G = open("grades.html","w")
- G.write(body)
- print "Your grades are in grades.html, open it with a browser."
- driver.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement