@dj2638/

UnkemptSpicyString

Python 2.7

No description

fork
loading
Files
  • main.py
  • grades Wednesday, 19. September 2018 08:04PM.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from __future__ import division
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time
from time import sleep
from datetime import datetime
import sys
import os

email = "[email protected]"
username = "20jacodavi"
password = "3x7o34kt123"

output = open(("grades {}.txt").format(datetime.fromtimestamp(time.time()).strftime("%A, %d. %B %Y %I:%M%p")), "w")

driver = webdriver.Safari()
config = {'pwrschool': {'home': 'https://powerschool.gkb.k12.in.us/public/',
                        'pltw-de': {'t1': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004327009&begdate=08/03/2017&enddate=10/06/2017&fg=T1',
                                    't2': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004327009&begdate=08/03/2017&enddate=10/06/2017&fg=T2',
                                    't3': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004327009&begdate=08/03/2017&enddate=10/06/2017&fg=T3',
                                    't4': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004327009&begdate=08/03/2017&enddate=10/06/2017&fg=T4'
                                    },
                        'spanish-1a': {'t1': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004331618&begdate=08/03/2017&enddate=10/06/2017&fg=T1',
                                       't2': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004331618&begdate=08/03/2017&enddate=10/06/2017&fg=T2',
                                       't3': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004331618&begdate=08/03/2017&enddate=10/06/2017&fg=T3',
                                       't4': 'https://powerschool.gkb.k12.in.us/guardian/scores.html?frn=004331618&begdate=08/03/2017&enddate=10/06/2017&fg=T4'
                                       }
                        },
          'pwrschool_signin': {'username': '//*[@id="fieldAccount"]',
                               'password': '//*[@id="fieldPassword"]',
                               'signin_btn': '//*[@id="btn-enter"]'
                               },
          'mylc': {'home': 'https://secure.mylcsolution.com/s2/student/front',
                   'progress': 'https://secure.mylcsolution.com/s2/student/?versionNotify=0#nav_goals',
                   'grades': 'https://secure.mylcsolution.com/s2/student/?versionNotify=0#nav_course_progress',
                   'chemistry-i': {'grade': '//*[@id="row_2094"]/td[6]',
                                   'current': '//*[@id="goalChart_27811"]/div/div[1]/div/svg/g[1]/g[4]/g[1]/g/g/text[2]',
                                   'expected': '//*[@id="goalChart_27811"]/div/div[1]/div/svg/g[1]/g[4]/g[2]/g/g/text[2]'
                                   },
                   'algebra-ii': {'grade': '//*[@id="row_1364"]/td[6]',
                                  'current': '//*[@id="goalChart_27812"]/div/div[1]/div/svg/g[1]/g[4]/g[1]/g/g/text[2]',
                                  'expected': '//*[@id="goalChart_27812"]/div/div[1]/div/svg/g[1]/g[4]/g[2]/g/g/text[2]'
                                  },
                   'english-10h': {'grade': '//*[@id="row_1857"]/td[6]',
                                   'current': '//*[@id="goalChart_29407"]/div/div[1]/div/svg/g[1]/g[4]/g[1]/g/g/text[2]',
                                   'expected': '//*[@id="goalChart_29407"]/div/div[1]/div/svg/g[1]/g[4]/g[2]/g/g/text[2]'
                                   }
                   },
          'mylc_signin': {'start_btn': '/html/body/div/div[2]/form/div[3]/div',
                          'username': '//*[@id="identifierId"]',
                          'password': '//*[@id="password"]/div[1]/div'
                          }
         }

def get_element(xpath):
    return WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.XPATH, xpath))
        )

def get_grades(grade_html_xpath, classname, classdict):
    grades = "{classname}\n    T1: {t1grade}\n    T2: {t2grade}\n    T3: {t3grade}\n    T4: {t4grade}"
    driver.get(classdict['t1'])
    t1grade = get_element(grade_html_xpath).text.encode('ascii', 'ignore').strip()
    driver.get(classdict['t2'])
    t2grade = get_element(grade_html_xpath).text.encode('ascii', 'ignore').strip()
    driver.get(classdict['t3'])
    t3grade = get_element(grade_html_xpath).text.encode('ascii', 'ignore').strip()
    driver.get(classdict['t4'])
    t4grade = get_element(grade_html_xpath).text.encode('ascii', 'ignore').strip()
    output.write(grades.format(classname=classname, t1grade=t1grade, t2grade=t2grade, t3grade=t3grade, t4grade=t4grade))
    output.write("\n")

def get_powerschool():
    grade_html_xpath = '//*[@id="content-main"]/div[3]/table/tbody/tr[2]/td[4]/text()[1]'
    output.write("\nPowerschool\n")
    driver.get(config['pwrschool']['home'])
    get_element(config['pwrschool_signin']['username']).send_keys(username)
    sleep(2)
    get_element(config['pwrschool_signin']['password']).send_keys(password)
    sleep(2)
    get_element(config['pwrschool_signin']['signin_btn']).click()
    sleep(2)
    get_grades(grade_html_xpath, "PLTW-DE", config['pwrschool']['pltw-de'])
    sleep(2)
    get_grades(grade_html_xpath, "Spanish 1A", config['pwrschool']['spanish-1a'])

def get_progress(grade_html_xpath, classname, classdict):
    grades = "{classname}\n       Grade: {grade}\n     Current: {current}\n    Expected: {expected}"
    driver.get(config['mylc']['grades'])
    grade = get_element(classdict['grade']).text.encode('ascii', 'ignore').strip()
    driver.get(config['mylc']['progress'])
    current = float(get_element(classdict['current']).text)
    expected = float(get_element(classdict['expected']).text)
    print grade
    print current
    print expected

def get_mylc():
    grade_html_xpath = ''
    output.write("\nMyLC\n")
    driver.get(config['mylc']['home'])
    get_element(config['mylc_signin']['start_btn']).click()
    sleep(2)
    driver.switch_to.window(driver.window_handles[1])
    get_element(config['mylc_signin']['username']).send_keys(email, Keys.RETURN)
    sleep(2)
    get_element(config['mylc_signin']['password']).send_keys(password, Keys.RETURN)
    sleep(2)
    driver.switch_to.window(driver.window_handles[0])
    sleep(2)
    get_progress(grade_html_xpath, "Chemistry I", config['mylc']['chemistry-i'])
    sleep(2)
    get_progress(grade_html_xpath, "Algebra II", config['mylc']['algebra-ii'])
    sleep(2)
    get_progress(grade_html_xpath, "English 10 Honors", config['mylc']['english-10h'])

def main():
    get_powerschool()
##    get_mylc()
    output.close()
    driver.quit()
    sys.exit(0)

main()