1 | var query = WScript.CreateObject("AlaxInfo.UaMobileTools.KyivstarUaBalanceQuery"); |
---|
2 | |
---|
3 | var log = ""; |
---|
4 | var messageBody = ""; |
---|
5 | var messageNeeded = false; |
---|
6 | |
---|
7 | function 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 | |
---|
27 | function 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 | |
---|
54 | Do("Roman", "+38096xxxxxxx", "password at my.kyvstar.ua", 10); |
---|
55 | //Do("Tablet", ... |
---|
56 | |
---|
57 | fileSystem = WScript.CreateObject("Scripting.FileSystemObject"); |
---|
58 | var textFilePath = "D:\\Projects\\Alax.Info\\Repository-Public\\Utilities\\UaMobileTools\\Script\\" + "Check.js.log"; |
---|
59 | textFile = fileSystem.OpenTextFile(textFilePath, 8, true); // ForAppending |
---|
60 | textFile.Write(log); |
---|
61 | textFile.Close(); |
---|
62 | |
---|
63 | if (messageNeeded) |
---|
64 | SendMessage(); |
---|