three-credit-checker v4.2 [30 Dec 2020] by Dominic
Description
Check and show remaining credit or allowances on phone accounts from Hutchison Three (H3G) mobile network in UK (https://www.three.co.uk/).
For pay-as-you-go (PAYG) phones it can check the remaining credit and in quiet mode will be silent unless the credit is below the warning level that you have set (in pounds). For pay-monthly (aka contract or PAYM) phones it can check the remaining minutes in the allowance, the remaining days (before renewing of allowances) and the remaining data, and show a warning if any of these are below your specified warning level.
Any 'unlimited' or 'all-you-can-eat' allowances are reported as '100000' - for easier post-processing.
Written in bash for use on Linux or (under Windows) Cygwin. Note the dependencies (below).
Conf_file
Account information should be in a conf file shown by the -c option. If this is unspecified three-credit-checker.sh will search for conf file three-credit-checker.conf in the same location as three-credit-checker.sh. In the conffile, each phone/account should be on a separate line thus (blank lines and lines beginning with a hash symbol are ignored):
nickname phonenumber password creditwarnlevel
# for a pay-monthly (PAYM) account (note: 4th parameter 'm' is not used)
nickname phonenumber password m minswarn 3-to-3minswarn dayswarn datawarn
Here is a 2-line conf file example:
janet 07421234567 H4rdNUMbrrr m 50 30 0 100
When three-credit-checker.sh is run using this example conf file it will generate a warning to the 'standard error' device if the credit on the first (PAYG) phone is below 2.25, and for the second phone it will generate a warning if there are, for this month, either 50 minutes or less left for normal calls, or 30 minutes or less left for 3-to-3 calls, or 0 days or less, or 100MB or less.
If you set any warning level to zero then no warnings will be issued for that parameter.
The 'nickname' can be any text to help you identify the phone, it is for local use only and is not passed to or matched against any data held by Three.
Exit Codes
0 - all completed and no warnings were issued
9 - failed to login successfully to one or more accounts
10 - all completed but one or more warnings were issued
other - an unexpected problem occurred
Options
-c conf_file - specify name and location of conf_file
-h - show help and exit
-l - show changelog and exit
-n nickname - only run for the given nickname (which must be listed in conffile)
-q - quiet mode - only show warnings or errors
-r - if redirectUrl page not found, pause 10m and retry - up to 5 times
-s - skip program title header and output data in csv format
-t - skip program title header (e.g. to pipe to column)
-v - verbose mode - show login progress
Dependencies
awk bash curl coreutils grep lynx sed
License
Copyright © 2020 Dominic Raferd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Changelog
4.2 [30 Dec 2020]: adapt for changes at My3 (PAYG only)
4.1 [18 Aug 2020]: adapt for changes at My3
4.0 [02 Apr 2020]: adapt for changes at My3
3.9 [27 Dec 2019]: show reason for login failure if provided in json
3.8 [18 Oct 2019]: updates for changes on My3 page
3.7 [05 Aug 2019]: make compatible with MacOS
3.6 [08 Jul 2019]: bugfix for when pages on My3 start with '.'
3.5 [13 Feb 2019]: adapt for change in data text on My3 page
3.4 [29 Aug 2018]: adapt for return of the login iframe
3.3 [12 Jul 2018]: bugfix, add exit code 9 if failure to login
3.2 [11 Jul 2018]: adapt for changes at My3 (now uses Ajax), no longer requires form-extractor
3.1 [05 Sep 2017]: replace checking of remaining texts by remaining days
3.0 [01 Jul 2017]: no longer 'pretend' to be Firefox
2.9 [21 May 2017]: skip (reporting error) if My3 page says it has 'problem'
2.8 [19 Oct 2016]: small change to match change on My3 website, small corrections to help text
2.7 [02 Jun 2016]: allow to work for different users
2.6 [25 May 2016]: small changes but probably not significant
2.5 [05 May 2016]: report if My3 is officially unavailable
2.4 [04 May 2016]: further adaptations, accommodate 'all-you-can-eat calls'
2.3 [11 Mar 2016]: adaptation for changes to Three website
2.2 [08 Feb 2016]: bugfix for PAYG, sometimes didn't pick up total credit
2.1 [11 Nov 2015]: bugfix - wasn't notifying when credit below warning level
2.0 [25 Jun 2015]: bugfixed and simplified data extraction by using lynx to create text version of web page
1.9 [18 May 2015]: move cookiejar files from /tmp to /var/tmp
1.8 [15 Apr 2015]: v small adaptation for change on Three's iframed-webpage
1.7 [07 Apr 2015]: bugfix
1.6 [27 Jan 2015]: minor bugfix with expiry date of bundle on PAYG
1.5 [04 Nov 2014]: minor bugfix with -s option
1.4 [03 Nov 2014]: add a nickname field, option -n now tests against this
1.3 [28 Oct 2014]: for PAYG, show free internet MB and expiry date
1.2 [27 Oct 2014]: add some permission checking
1.1 [26 Aug 2014]: bugfix to overcome a Three website change
1.0 [17 Jul 2014]: with 'all-you-can-eat data' add-on, report data MB as 100000
0.9 [20 May 2014]: add -r option
0.8 [10 May 2014]: exit with code 10 if one or more warnings were issued
0.7 [25 Apr 2014]: improve help text, skip blank lines in conf file
0.6 [14 Apr 2014]: report if My3 is offline
0.5 [09 Apr 2014]: add -n and -s options, -s output optimized for data analysis, conf file format changed a little
0.4 [03 Apr 2014]: code and help info improvements, add detection of 3-to-3 minutes
0.3 [02 Apr 2014]: help text changes, first public release
0.2 [17 Mar 2014]: for pay-monthly, check remaining text and data
0.1 [13 Mar 2014]: first version
Download three-credit-checker.sh
Donation
I have provided this software free gratis and for nothing. If you would like to thank me with a contribution, please let me know and I will send you a link. Thank you!
My Other Sites
- TimeDicer - Onsite/offsite data backup for Windows (uses rdiff-backup)
- Finding a 4D Backup Solution
- Web Scraping How To - extracting data from web sites
My Programs
Here is a selection of some (other) programs I have written, most of which run under GNU/Linux from the command line (CLI), are freely available and can be obtained by clicking on the links. Dependencies are shown and while in most cases written and tested on an x86-based Linux server, they should run on a Raspberry Pi, and many can run under Windows using Windows Subsystem for Linux (WSL) or Cygwin. Email me if you have problems or questions, or if you think I could help with a programming requirement.
Backup Utilities
- TimeDicer - Onsite/offsite data backup for Windows (uses rdiff-backup) [ GNU/Linux & MS Windows©: 2008-20 ]
- rdiff-backup-regress - GNU/Linux script to regress an rdiff-backup archive. [ GNU/Linux: 2012-16 ]
Debian/Ubuntu kernel and LVM Utilities
- kernel-remove - GNU/Linux script to list the installed GNU/Linux kernels in a Debian-based distro (e.g. Ubuntu), and can be used to remove an unwanted kernel and related packages, updating grub appropriately. [ GNU/Linux-Debian/Ubuntu: 2010-22 ]
- lvm-usage - GNU/Linux script to show available disk space and how it is used; run as cron job to warn if usage is above a set percentage. Provides additional information if LVM is in use. [ GNU/Linux: 2012-23 ]
- lvm-delete-snapshot - GNU/Linux script to remove LVM snapshot that has been left over by another process. [ GNU/Linux: 2012-21 ]
- netnames - GNU/Linux script shows current name, biosdevname and 'predictable name' of network device - helps with network device name scheme migration. [ GNU/Linux-Debian/Ubuntu: 2020-20 ]
- lv-convert2cache - GNU/Linux script to convert an existing LV into a cache LV using a smaller faster device as a cache. [ GNU/Linux: 2022-23 ]
Miscellaneous Programs
- sleepwalker - Windows© program which can be run from a remote machine to 'wake up' a Windows© machine behind a router, wait for it to start and then initiate Remote Desktop session. [MS Windows©: 2008-22]
- numliststat - GNU/Linux program giving statistical value(s) for a piped-in list of numbers. [ GNU/Linux: 2022-22 ]
- relay-enforcer - GNU/Linux program enabling a postfix-based mail server relaying to Gmail to act on reports from Gmail about blocked emails. [ GNU/Linux: 2016-24 ]
- pdf-compress - GNU/Linux program to create smaller b/w pdf file from an original large pdf file, especially when original resulted from scanning. [ GNU/Linux: 2016-23 ]
- tiny-device-monitor - GNU/Linux program to test webpages (including password-protected) or machines to check they are live; use as a cron job for your own websites, for hardware presenting a webpage, or for any machines with a presence on your local LAN or on the internet. [ GNU/Linux: 2009-24 ]
- form-extractor - GNU/Linux program to extract form tags from a web page or downloaded file. [ GNU/Linux: 2012-20 ]
- mythic-dns-sync - GNU/Linux program to update DNS record at mythic-beasts.com to match local external ip. [ GNU/Linux: 2016-23 ]
- saynoto0870 - For UK, a GNU/Linux script which performs automated lookup of the www.saynoto0870.com database, finding cheap or free geographic number replacements for expensive non-geographic (087* or 084*) numbers. [ GNU/Linux: 2012-12 ]
- bind9-resolved-switch - GNU/Linux program for switching permanently between using bind9 or systemd-resolved as the system DNS resolver. [ GNU/Linux: 2016-22 ]
- unlock - GNU/Linux remote program for easy entering of decrypt passphrase on a remote machine which has root dm-crypt+LUKS. [ GNU/Linux: 2017-18 ]
- wifi-updown - GNU/Linux program to take down wifi interface if there is a working wired interface (or restore wifi if not). [ GNU/Linux: 2018-23 ]
- routefix - GNU/Linux program to restore a default ip traffic route if there is none such (e.g. after running wifi-updown). [ GNU/Linux: 2018-23 ]
- dutree - GNU/Linux program to show a tree-style list of files and directories at the specified location which are greater than the specified size (default 1GB). [ GNU/Linux: 2012-24 ]
- Accounts - Multi-business multi-currency accounting software, uses Access [MS Windows©: 1996-2024]
- Rents Program - Residential lettings/landlord front office program, with many special features for UK market [MS Windows©: 1991-2024]
This section is closed. If you have a question, please submit it by email, thank you.
Paul.
Thanks also for this -- it looks like it should be very useful. I'm trying to do the same as David. Unfortunately it doesn't seem to work with either of the Three prepay accounts we have. The (slightly bowdlerised by missing out the start of each address) verbose output is:
Loop 1 - New_My3/My3_Home - authenticated, get homepage:
Loop 2 - New_My3/My3_Home - form response:
Loop 3 - New_My3/My3_Home - form response:
Loop 4 - New_My3/My3_Home - form response:
Loop 5 - New_My3/My3_Home - form response:
Loop 6 - New_My3/My3_Home - form response:
dominic (07abcabcabc) unable to login...
This is with version 3.9, using bash Debian 10, with bash 5.0.3 on Debian. If I'm interpreting that correctly, it looks like it's authenticating, but then failing after that. Do you know whether something has changed with the home page?
Many thanks, Paul.
Are you able to confirm if the script still works as is?
Thanks, Paul