source: trunk/Utilities/UaMobileTools/Script/Check - Template.js @ 937

Last change on this file since 937 was 106, checked in by roman, 12 years ago
File size: 2.1 KB
Line 
1var query = WScript.CreateObject("AlaxInfo.UaMobileTools.KyivstarUaBalanceQuery");
2
3var log = "";
4var messageBody = "";
5var messageNeeded = false;
6
7function Do(alias, number, password, threshold) {
8    try {
9        query.Initialize(number, password);
10        log = log +
11                (new Date).toLocaleString() + "\t" +
12                alias + "\t" +
13                query.Number + "\t" +
14                query.Balance.toFixed(2) + //"\t" +
15                "\r\n";
16        messageBody = messageBody + alias + ": " + query.Balance.toFixed(2) + "; ";
17        messageNeeded |= query.Balance < threshold;
18    } catch (error) {
19        log = log +
20            (new Date).toLocaleString() + "\t" +
21            alias + "\t" +
22            error.message + //"\t" +
23            "\r\n";
24    }
25}
26
27function SendMessage() {
28    message = WScript.CreateObject("AlaxInfo.EmailTools.Message");
29    message.ServerHost = "smtp.gmail.com";
30    message.Sender = "\"Balance Check\" <a@b.c>";
31    message.ToRecipients = "38096xxxxxxx@sms.kyivstar.net";
32    message.CcRecipients = "a@b.c";
33    message.Subject = "Balance Check";
34    message.Body = messageBody;
35    message.TransportLayerSecurity = true;
36    message.AuthMethods = "login";
37    message.AuthName = "a@b.c";
38    message.AuthPassword = "password";
39    for (attempt = 0; attempt < 1 * 60 * 4; attempt++) { // 1 hour
40        WScript.Echo("Trying to send email, attempt " + attempt.toString() + "...");
41        try {
42            message.Send();
43            WScript.Echo("Sent");
44            return true;
45        }
46        catch (error) {
47            WScript.Echo(error.message);
48        }
49        WScript.Sleep(15 * 1000); // 15 seconds
50    }
51    return false;
52}
53
54Do("Roman", "+38096xxxxxxx", "password at my.kyvstar.ua", 10);
55//Do("Tablet", ...
56
57fileSystem = WScript.CreateObject("Scripting.FileSystemObject");
58var textFilePath = "D:\\Projects\\Alax.Info\\Repository-Public\\Utilities\\UaMobileTools\\Script\\" + "Check.js.log";
59textFile = fileSystem.OpenTextFile(textFilePath, 8, true); // ForAppending
60textFile.Write(log);
61textFile.Close();
62
63if (messageNeeded)
64    SendMessage();
Note: See TracBrowser for help on using the repository browser.