From: martin f. krafft Date: Fri, 8 Dec 2017 10:04:19 +0000 (+0100) Subject: initial checkin X-Git-Url: https://git.madduck.net/code/wifionice-login.git/commitdiff_plain/c5232e694a14db2bc041dc5476c19a1b01e5b406?ds=sidebyside initial checkin --- c5232e694a14db2bc041dc5476c19a1b01e5b406 diff --git a/wifionice-login b/wifionice-login new file mode 100755 index 0000000..2b5abff --- /dev/null +++ b/wifionice-login @@ -0,0 +1,32 @@ +#!/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))