From 79fab7d384798bce13b7f74011bb6797dd73b8b0 Mon Sep 17 00:00:00 2001 From: IdarV Date: Wed, 7 Oct 2015 16:03:39 +0200 Subject: [PATCH] resolves #3 --- README.md | 9 +++++---- main.py | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) 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 f4431aa..6d7bcdc 100644 --- a/main.py +++ b/main.py @@ -5,23 +5,22 @@ parser = SafeConfigParser() parser.read('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') @@ -29,11 +28,11 @@ course_name = inner_tags[1].text.split("\n")[1] grade = inner_tags[5].text if grade != 'Passed': - chars.append(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': @@ -49,7 +48,7 @@ -finalChar = total/len(chars) +finalChar = total/len(grades) print ('----------------------------------') print ('Din naavaerende karakter er: ' + str(finalChar))