#!/usr/bin/python3 # © 2017 martin f. krafft # Released under the terms of the Artistic Licence 2.0 # https://git.madduck.net/code/wifionice-login.git URL='http://www.wifionice.de/de/?login' import sys if len(sys.argv) != 2: sys.stderr.write('E: missing action, need {login,logout}\n') sys.exit(1) ACTION=sys.argv[1] if ACTION not in ('login', 'logout'): sys.stderr.write('E: invalid action: {}\n'.format(sys.argv[1])) sys.exit(1) import mechanicalsoup browser = mechanicalsoup.StatefulBrowser() browser.open("http://www.wifionice.de/de/?login") page = browser.get_current_page() if page.body.form.input['name'] == ACTION: sys.stderr.write('I: performing {}…\n'.format(ACTION)) form = browser.select_form('form') browser.submit(form, url=URL) else: sys.stderr.write('I: nothing to do for {}.\n'.format(ACTION))