diff --git a/README.md b/README.md index a5031ea..7006bc6 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,11 @@ Hench why studcli was born, now you can easily call a python-command, and all yo ## How to use 1. Make sure you have Python installed 2. Install splinter via pip -3. Download the script. -4. Edit config.ini with your info and prefered settings -5. Run main.py using the python-command (python2) -6. (optionally) add ```alias studweb="python /path/to/studcli/main.py"``` in your zshconfig, so that you can run ```studweb``` from terminal +3. Install phantomjs ```sudo apt-get install phantomjs``` +4. Download the script. +5. Edit config.ini with your info and prefered settings +6. Run main.py using the python-command (python2) +7. (optionally) add ```alias studweb="python /path/to/studcli/main.py"``` in your zshconfig, so that you can run ```studweb``` from terminal ## Disclaimer I made this for my own sake, and it may or may not work on your studweb. \ No newline at end of file diff --git a/main.py b/main.py index 18e9473..f8aa665 100644 --- a/main.py +++ b/main.py @@ -7,23 +7,22 @@ parser = ConfigParser.ConfigParser() parser.read(os.path.join(os.path.dirname(__file__), 'config.ini')) -browser = Browser(parser.get('Config', 'Browser')) -browser.driver.maximize_window() +browser = Browser('phantomjs') +browser.cookies.delete() +browser.driver.set_window_size(1920,1080) -browser.visit('https://fsweb.no/studentweb/login.jsf?inst=' + parser.get('Config', 'Institution')) -browser.find_by_text('Norwegian ID number and PIN').first.click() +browser.visit('http://fsweb.no/studentweb/login.jsf?inst=FSWACT') +browser.find_by_xpath("//div[@id='login-box']/div[@id='login-flaps']/div[@class='login-flap login-name-pin']").click() -browser.find_by_id('login-box') browser.fill('j_idt129:j_idt131:fodselsnummer', parser.get('Config', 'Fodselsnummer')) browser.fill('j_idt129:j_idt131:pincode', parser.get('Config', 'Pin')) -browser.find_by_text('Log in').first.click() -browser.click_link_by_href('/studentweb/resultater.jsf') +browser.find_by_xpath("//button[@id='j_idt129:j_idt131:login']").click() +browser.find_by_xpath("//nav[@id='menuBarLeft']/ul[@class='mainmenu']/li/a[@title='Resultater']").click() +grades = [] tags = browser.find_by_tag('tr') -chars = [] - for tag in tags: if tag.has_class('resultatTop') or tag.has_class('none'): inner_tags = tag.find_by_tag('td') @@ -31,12 +30,11 @@ course_name = inner_tags[1].text.split("\n")[1] grade = inner_tags[5].text if grade != 'Passed': - chars.append(grade) - - print "%s\t%-30s\t%s" % (course_id, course_name, grade) + grades.append(grade) + print "%s\t%-30s\t%s" % (course_id, course_name, grade) total = 0.0 -for char in chars: +for char in grades: if char == 'A': total += 6 elif char == 'B': @@ -52,7 +50,7 @@ -finalChar = total/len(chars) +finalChar = total/len(grades) print ('------------------------------------------') print ('Ditt nåværende karaktersnitt er: ' + str(finalChar))