Requires: python3: requests
Usage: run using python (python main.py
).
Caution: saves credentials in plaintext as cred.json
in the directory from which it is executed. Changing permissions on this file is recommended.
Steps for setting up a cron job:
- Run the script once, so that
cred.json
is created. - Install cron (
cronie
- forapt
-using distros, runapt install cronie
). - Enable the cron daemon (systemd:
systemctl enable cronie && systemctl start cronie
, usually requires sudo) - Create a cron file (
crontab -e
) - Write the jobs:
15,45 * * * * python /path/to/netaccess/main.py >> /tmp/cron.log 2>&1
@reboot sleep 15 && python /path/to/netaccess/main.py
Explanation: first line repeats auth every hour at 15 and 45 minutes, second line auths 15 seconds after a reboot.
Note: replace path/to with the path of the script.
-
Save the file. Exit editor. This will write the crontab to the default location (
/var/spool/cron/{user}
usually). -
Verify that crontab is correctly saved:
crontab -l
. That's all!
- Auth failure/JSON error? Run it manually again.
- crontab listing showed nothing? Are you using VS Code as your default editor? Please use a command-line editor. Temporarily change it back by exporting
EDITOR
andVISUAL
tovim
,vi
, ornano
. Then edit crontab again (step 3). - Can't tell which failure it is? Check
/tmp/cron.log
. If it doesn't exist, cron has not executed the job.
Possible features:
- build automation of cron and power events into a one-run solution (automate.py) 1b. allow disabling of cron job/authorizing
- store creds in a more secure fashion. (use keyring)
- make connection failures more graceful.
- load a cat gif when successfully authorized
Historical/Contributions:
-
de-authorize before authorizing again: (netaccess does not seem to extend duration on reauthorizing). By Dragon-S1: netaccess does not need deauth. Also, it rounds off auth to (currently) hour:03, so next trigger can be predicted and cycles saved.
-
reduce the extra disk read when writing credentials for the first time. Fixed by Dragon-S1.
-
allow duration selection. Removed from todos: hour selection seems unnecessary. Instead can build a pause feature, if we control scheduling.
-
handle json format errors. Done by V3D3.
Contributors: Akshat Meena (Dragon-S1) Vedaant Arya (V3D3)