Recently I signed up my mobile to Telstra’s Next-G Network on a casual plan. Because I use a pre-paid data pack to access my hosted exchange mailbox, I need to keep track of that usage. Fortunately Telstra provides a MyDataUsage website that you can register for and logon to track your usage on a day-to-day basis. They’ll even send you an SMS when you’re 80% of your quota and again at 100% of your quota.
To keep a better eye on my usage I decided to use the WatiN Web Application Testing framework to drive the website using Internet Explorer automation. Here’s the code for anybody else who wants it:
IE ie = new IE(”https://es.telstra.com/MyDataUsage/”, true);
ie.TextField(Find.ByName(”USER”)).TypeText(”username“);
ie.TextField(Find.ByName(”PASSWORD”)).TypeText(”password“);
ie.Link(Find.ByUrl(”javascript:SubmitForm();”)).Click();
ie.Link(Find.ByUrl(”https://es.telstra.com/MyDataUsage/datausage.jsp”)).Click();ie.SelectList(Find.ByName(”txtService”)).Select(”Mobile Data Usage”);
string pattern = “You have currently used (?<PercentUsed>(.*))%\\((?<Usage>(.*))\\) of your (?<Quota>(.*)) included data.”;
string result = ie.FindText(new Regex(pattern));Match match = Regex.Match(result, pattern);
string percentUsed = match.Groups["PercentUsed"].Value;
string usage = match.Groups["Usage"].Value;
string quota = match.Groups["Quota"].Value;Console.WriteLine(”{0} out of {1}. {2}% used”, usage, quota, percentUsed);
So now I have a simple console app that I can run at anytime to see my usage.
The next step is to make it a Vista gadget, or a personal dashboard widget with other stats that I care about. e.g. home ADSL usage, etc.
One Trackback
[...] Link to Telstra Mobile Data Usage script « Grant Holliday [...]