<commit_before>from bs4 import BeautifulSoup
from Tkinter import *
import mechanize, re

cj = mechanize.CookieJar()
br = mechanize.Browser()

def decodeString(inpt):
    keyStr = "<KEY>
    output = ""
    i=0
    while i < len(inpt):

        enc1 = keyStr.find(inpt[i])
        i=i+1
        enc2 = keyStr.find(inpt[i])
        i=i+1
        enc3 = keyStr.find(inpt[i])
        i=i+1
        enc4 = keyStr.find(inpt[i])
        i=i+1
        
        chr1 = (enc1 << 2) | (enc2 >> 4)
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2)
        chr3 = ((enc3 & 3) << 6) | enc4
        output = output + chr(chr1)
        
        if enc3 != 64:
            output = output + chr(chr2)

        if enc4 != 64:
            output = output + chr(chr3)
    return output

def inDepthDL(ending):
    link = "https://gradespeed.kleinisd.net/pc/ParentStudentGrades.aspx"+ending
    try:
        br.open(link)
    except Exception:
        print "Sorry. There was an error."
    
    return 1

def GUIprintSel(Titles, Matrix, Child, oneStudent):
    GUISel = Tk()
    GUISel.title(Child)
    for headers in range(1,len(Titles)):
        Label(GUISel, text=Titles[headers].contents[0]).grid(row=0, column=headers-1)
    for rows in range(len(Matrix)):
        res="";
        holda = 1
        for columns in range(len(Matrix[rows])):
            temp=""
            isLink = False
            try:
                try:
                    temp = str(Matrix[rows][columns]).split(">")[1].split("<")[0]
                    isLink=True
                except Exception:
                    temp = str(Matrix[rows][columns][0])
            except: temp = "-"
            holda=holda+1
            if isLink:
                Label(GUISel,text=temp).grid(row=rows+1, column=columns)
            else:
                Label(GUISel,text=temp).grid(row=rows+1, column=columns)
    if oneStudent==False:
        Button(GUISel,text="Select Student").grid(row=len(Matrix)+1,column=0,columnspan=len(Matrix[1]))
    GUISel.mainloop()

def tableGet(options, oneStudent, iterator, namHold):
    if oneStudent!=True:
        name = str(namHold)
        name=name.split("label='")[iterator+1].split("'")[0]
        print name
        br.select_form("aspnetForm")
        studCaux = br.form.find_control(nr=10)
        studCaux.value = [options.name]
        print "Loading..."
        br.submit()
    
    oGrade = br.follow_link(text_regex="Grades")
    oPage = oGrade.read()
    if oneStudent:
        narrowed = oPage.split("var")[2].split("document.write")[0].split("'")
    else:
        narrowed = oPage.split("var")[3].split("document.write")[0].split("'")
    code=""
    for i in range(3,len(narrowed)):
        if i%2==1:
            code=code+narrowed[i]
    
    rawhtml = decodeString(code)
    woU8 = rawhtml.replace("&nbsp;","")

    getTableDat = BeautifulSoup(woU8)
    getTableDat.prettify()
    fRow=getTableDat.findAll("tr")
    tempCols = BeautifulSoup(str(fRow[0]))
    Cols = tempCols.findAll("th")
    numOCols= len(Cols)-1
    indexList = getTableDat.findAll("td")
    
    extracted = []
    
    for rows in indexList:
        extracted.append(rows.contents)

    matric = []
    
    for i in range(len(extracted)/numOCols):
        holder = []
        for j in range(numOCols):
            try:
                holder.append(extracted[i*numOCols+j])
            except Exception:
                holder.append([])
        matric.append(holder)

    print "Done! Press exit to go to the next student."
    print

    if oneStudent!=True:
        GUIprintSel(Cols, matric, name, oneStudent)
    else:
        GUIprintSel(Cols, matric, "1st", oneStudent)

def cycleStuff(userNm, passWd):
    
    Continue = True
    
    try:
        br.open("https://gradespeed.kleinisd.net/pc/Default.aspx")
    except Exception:
        print "Please check if you are connected to the internet."
        Continue = False
        
    if Continue:
        br.select_form("Form1")
        
        userCtrl = br.form.find_control("txtUserName")
        passwrdCtrl = br.form.find_control("txtPassword")
        
        userCtrl.value = userNm
        passwrdCtrl.value = <PASSWORD>

        response = br.submit()
        try:
            br.select_form("aspnetForm")
        except Exception:
            print "Incorrect Username and/or Password."
            Continue = False
            
        if(Continue):
            oneStudent=False
            
            try:
                studC = br.form.find_control(nr=10)
            except Exception:
                oneStudent = True

            if oneStudent:
                tableGet(["BLARRRGHHH!"], oneStudent, 0, ["Trolol"])
            else:
                it=0
                for options in studC.items:
                    tableGet(options, oneStudent, it, studC.items)
                    it=it+1
        else:
            logGUIMeth()
    else:
        logGUIMeth()    

def logGUIMeth():
    def getLogin():
        uTemp=userHold.get()
        pTemp=passHold.get()
        logGUI.destroy()
        cycleStuff(uTemp,pTemp)
        return
    def entLog(evt):
        getLogin();
        return
    logGUI = Tk()
    logGUI.geometry("200x200+250+250")
    logGUI.title("Login Window")
    Label(logGUI,text="").pack()
    logSign = Label(logGUI,text="Login to GradeSpeed").pack()
    Label(logGUI,text="").pack()
    userSign = Label(logGUI,text="Username:").pack()
    userHold = StringVar()
    userField = Entry(logGUI,textvariable=userHold)
    userField.pack()
    userField.bind("<Key-Return>", entLog)
    Label(logGUI,text="").pack()
    passSign = Label(logGUI,text="Password:").pack()
    passHold = StringVar()
    passField = Entry(logGUI,textvariable=passHold, show = "*")
    passField.pack()
    passField.bind("<Key-Return>", entLog)
    Label(logGUI,text="").pack()
    okBut = Button(text="Login",command=getLogin).pack()
    logGUI.mainloop()

def main():
    br.set_cookiejar(cj)
    br.set_handle_robots(False)
    br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0')]
    logGUIMeth()

if __name__ == "__main__":
    main()
<commit_msg>Student Selection Implemented<commit_after>from bs4 import BeautifulSoup
from Tkinter import *
import mechanize, re

cj = mechanize.CookieJar()
br = mechanize.Browser()

def decodeString(inpt):
    keyStr = "<KEY>
    output = ""
    i=0
    while i < len(inpt):

        enc1 = keyStr.find(inpt[i])
        i=i+1
        enc2 = keyStr.find(inpt[i])
        i=i+1
        enc3 = keyStr.find(inpt[i])
        i=i+1
        enc4 = keyStr.find(inpt[i])
        i=i+1
        
        chr1 = (enc1 << 2) | (enc2 >> 4)
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2)
        chr3 = ((enc3 & 3) << 6) | enc4
        output = output + chr(chr1)
        
        if enc3 != 64:
            output = output + chr(chr2)

        if enc4 != 64:
            output = output + chr(chr3)
    return output

def studentSel(studys):
    name = str(studys)
    fname = name.split("label='")[1].split("'")[0]
    names=[fname]
    for i in range(1,len(studys)):
        names.append(name.split("label='")[i+1].split("'")[0])
    def buttPress():
        inde=0
        daTemp = var.get()
        for i in range(1,len(names)):
            if str(daTemp) in str(names[i]):
                inde = i
        studSel.destroy()
        tableGet(studys[inde], False, inde, studys)
    studSel = Tk()
    var = StringVar()
    var.set(fname)
    Label(text="Select a student:").grid(row=0, column=0, columnspan=2)
    OptionMenu(studSel, var, *names).grid(row=1, column=0, columnspan=2)
    Button(text="Continue", command=buttPress).grid(row=2, column=0, columnspan=2)
    studSel.mainloop()
    

def inDepthDL(ending):
    link = "https://gradespeed.kleinisd.net/pc/ParentStudentGrades.aspx"+ending
    try:
        br.open(link)
    except Exception:
        print "Sorry. There was an error."
    
    return 1

def GUIprintSel(Titles, Matrix, Child, oneStudent, holdy):
    def studSelBut():
        GUISel.destroy()
        studentSel(holdy)
    GUISel = Tk()
    GUISel.title(Child)
    for headers in range(1,len(Titles)):
        Label(GUISel, text=Titles[headers].contents[0]).grid(row=0, column=headers-1)
    for rows in range(len(Matrix)):
        res="";
        holda = 1
        for columns in range(len(Matrix[rows])):
            temp=""
            isLink = False
            try:
                try:
                    temp = str(Matrix[rows][columns]).split(">")[1].split("<")[0]
                    isLink=True
                except Exception:
                    temp = str(Matrix[rows][columns][0])
            except: temp = "-"
            holda=holda+1
            if isLink:
                Label(GUISel,text=temp).grid(row=rows+1, column=columns)
            else:
                Label(GUISel,text=temp).grid(row=rows+1, column=columns)
    if oneStudent==False:
        Button(GUISel,text="Select Student", command=studSelBut).grid(row=len(Matrix)+1,column=0,columnspan=len(Matrix[1]))
    GUISel.mainloop()

def tableGet(options, oneStudent, iterator, namHold):
    if oneStudent!=True:
        name = str(namHold)
        name=name.split("label='")[iterator+1].split("'")[0]
        print name
        br.select_form("aspnetForm")
        studCaux = br.form.find_control(nr=10)
        studCaux.value = [options.name]
        print "Loading..."
        br.submit()
    
    oGrade = br.follow_link(text_regex="Grades")
    oPage = oGrade.read()
    if oneStudent:
        narrowed = oPage.split("var")[2].split("document.write")[0].split("'")
    else:
        narrowed = oPage.split("var")[3].split("document.write")[0].split("'")
    code=""
    for i in range(3,len(narrowed)):
        if i%2==1:
            code=code+narrowed[i]
    
    rawhtml = decodeString(code)
    woU8 = rawhtml.replace("&nbsp;","")

    getTableDat = BeautifulSoup(woU8)
    getTableDat.prettify()
    fRow=getTableDat.findAll("tr")
    tempCols = BeautifulSoup(str(fRow[0]))
    Cols = tempCols.findAll("th")
    numOCols= len(Cols)-1
    indexList = getTableDat.findAll("td")
    
    extracted = []
    
    for rows in indexList:
        extracted.append(rows.contents)

    matric = []
    
    for i in range(len(extracted)/numOCols):
        holder = []
        for j in range(numOCols):
            try:
                holder.append(extracted[i*numOCols+j])
            except Exception:
                holder.append([])
        matric.append(holder)

    print "Done!"
    print

    if oneStudent!=True:
        GUIprintSel(Cols, matric, name, oneStudent, namHold)
    else:
        GUIprintSel(Cols, matric, "1st", oneStudent, namHold)

def cycleStuff(userNm, passWd):
    
    Continue = True
    
    try:
        br.open("https://gradespeed.kleinisd.net/pc/Default.aspx")
    except Exception:
        print "Please check if you are connected to the internet."
        Continue = False
        
    if Continue:
        br.select_form("Form1")
        
        userCtrl = br.form.find_control("txtUserName")
        passwrdCtrl = br.form.find_control("txtPassword")
        
        userCtrl.value = userNm
        passwrdCtrl.value = <PASSWORD>

        response = br.submit()
        try:
            br.select_form("aspnetForm")
        except Exception:
            print "Incorrect Username and/or Password."
            Continue = False
            
        if(Continue):
            oneStudent=False
            
            try:
                studC = br.form.find_control(nr=10)
            except Exception:
                oneStudent = True

            if oneStudent:
                tableGet(["BLARRRGHHH!"], oneStudent, 0, ["Trolol"])
            else:
                studentSel(studC.items)
        else:
            logGUIMeth()
    else:
        logGUIMeth()    

def logGUIMeth():
    def getLogin():
        uTemp=userHold.get()
        pTemp=passHold.get()
        logGUI.destroy()
        cycleStuff(uTemp,pTemp)
        return
    def entLog(evt):
        getLogin();
        return
    logGUI = Tk()
    logGUI.geometry("200x200+250+250")
    logGUI.title("Login Window")
    Label(logGUI,text="").pack()
    logSign = Label(logGUI,text="Login to GradeSpeed").pack()
    Label(logGUI,text="").pack()
    userSign = Label(logGUI,text="Username:").pack()
    userHold = StringVar()
    userField = Entry(logGUI,textvariable=userHold)
    userField.pack()
    userField.bind("<Key-Return>", entLog)
    Label(logGUI,text="").pack()
    passSign = Label(logGUI,text="Password:").pack()
    passHold = StringVar()
    passField = Entry(logGUI,textvariable=passHold, show = "*")
    passField.pack()
    passField.bind("<Key-Return>", entLog)
    Label(logGUI,text="").pack()
    okBut = Button(text="Login",command=getLogin).pack()
    logGUI.mainloop()

def main():
    br.set_cookiejar(cj)
    br.set_handle_robots(False)
    br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0')]
    logGUIMeth()

if __name__ == "__main__":
    main()

{'fraction_non_alphanumeric': 0.13986548456129624, 'fraction_numerical': 0.01712014674411495, 'mean_word_length': 2.1598647669645015, 'pattern_counts': {'":': 2, '<': 27, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '616557', 'n_tokens_mistral': 4474, 'n_tokens_neox': 4293, 'n_words': 801}