diff --git a/pymarks.py b/pymarks.py index 36b924c..ed61a50 100644 --- a/pymarks.py +++ b/pymarks.py @@ -1,9 +1,6 @@ -# -*- coding: utf-8 -*- -from __future__ import print_function from getpass import getpass -import mechanize -import re -import bs4 +from robobrowser import RoboBrowser +from re import compile url = 'https://galilei-cr-sito.registroelettronico.com/' url_main = url + 'news' @@ -14,22 +11,21 @@ materie = {} br = mechanize.Browser() br.set_handle_robots(False) +br = RoboBrowser(history=False) def login(user, password): '''Effetua l'autenticazione''' br.open(url_login) - # Seleziona il primo form - br.select_form(nr=0) - - # Nell'username mette l'username, nella password la password - br.form['username'] = user - br.form['password'] = password - r = br.submit() + # Fill in the login form + form = br.get_form(id='loginform') + form['username'].value = user + form['password'].value = password + br.submit_form(form) # Se non compare 'errati' si รจ autenticati - if 'errati' in r.read(): + if 'errati' in br.response.text: return False else: return True @@ -112,7 +108,7 @@ def _mostra_voti(): print('%d. %s' % (i + 1, materia)) while True: print('') - id = int(raw_input('Materia: ')) + id = int(input('Materia: ')) if id in range(15): nome = materie.keys()[id - 1] voti = get_voti(nome) @@ -127,7 +123,7 @@ def main(): # Autenticazione logged = False while not logged: - user, password = raw_input('Username: '), getpass('Password: ') + user, password = input('Username: '), getpass('Password: ') logged = login(user, password) if not logged: print('Autenticazione fallita, riprovare.') @@ -144,10 +140,10 @@ def main(): _mostra_voti() elif scelta == 'm': _mostra_medie() - raw_input() + input() if __name__ == '__main__': try: main() except KeyboardInterrupt: - pass + print('')