menuimage

Description

Conf_file

Exit_Codes

Options

Dependencies

License

Changelog

Download

Donation

My_Other_Sites

My_Programs

Comments

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):

# for a pay-as-you-go (PAYG) account
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:

jimjones 07465987654 myPassword 2.25
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

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

Debian/Ubuntu kernel and LVM Utilities

Miscellaneous Programs

Comments

This section is closed. If you have a question, please submit it by email, thank you.

Another Paul 19 Apr 2020, 18:03
Just to confirm: Version 4.0 fixes this issue, and it now works perfectly. Thanks again!

Paul.
Another Paul 19 Apr 2020, 15:47
Hi Dominic.

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.
Dominic Raferd 05 Aug 2019, 07:43
@Paul - answered by email
Paul 04 Aug 2019, 18:25
Hi Dominic, thanks for the three-credit-checker, unfortunately it's not working for me and I wonder if it's to do with more changes to the three login? I'm running this on a Mac (I have all the dependencies installed)

Are you able to confirm if the script still works as is?

Thanks, Paul
David Nicol 22 Aug 2018, 12:41
Thanks re three credit checket. I had had a python script which did the same and I had had running for a long time under homeassistant till they changed the login in July. I now lazily shell out to your bash script - thanks!