瀏覽代碼

add more options to config file

Karathan 6 年之前
父節點
當前提交
e9519ce9de
共有 1 個檔案被更改,包括 14 行新增6 行删除
  1. 14
    6
      AuctionTracker/Program.cs

+ 14
- 6
AuctionTracker/Program.cs 查看文件

@@ -18,12 +18,17 @@ namespace AuctionTracker
18 18
 {
19 19
     class Program
20 20
     {
21
+        const string SHORT_DURATION = "SHORT";
21 22
         private static BlizzSharpClient _client;
22 23
         private static PushClient _pushClient;
23 24
         private static IEnumerable<Auction> lastAuctions;
24 25
         private static IConfiguration _configuration;
25 26
         private static ILog _logger;
26 27
 
28
+        private static string _character;
29
+        private static string _locale;
30
+        private static string _realm;
31
+
27 32
         private static string FormatCurrency(long full)
28 33
         {
29 34
             long gold = full / 10000;
@@ -33,8 +38,9 @@ namespace AuctionTracker
33 38
         }
34 39
         private static async Task RunUpdate()
35 40
         {
36
-            AuctionResponse response = await _client.GetAuctionsAsync("Khaz'goroth", "en_GB");
37
-            IEnumerable<Auction> auctions = response.Auctions.Where(a => a.Owner == "Karathan");
41
+            _logger.Info($"Running Update for {_character} on {_realm}");
42
+            AuctionResponse response = await _client.GetAuctionsAsync(_realm, _locale);
43
+            IEnumerable<Auction> auctions = response.Auctions.Where(a => a.Owner == _character);
38 44
             if(lastAuctions != null)
39 45
             {
40 46
                 HashSet<Auction> expiredAuctions = new HashSet<Auction>();
@@ -44,8 +50,8 @@ namespace AuctionTracker
44 50
                     if(!auctions.Any(b => b.Id == a.Id))
45 51
                     {
46 52
                         //the auction is now gone, but why?
47
-                        Item item = await _client.GetItemInfoAsync(a.Item, "en_GB");
48
-                        if(a.TimeLeft == "SHORT")
53
+                        Item item = await _client.GetItemInfoAsync(a.Item, _locale);
54
+                        if(a.TimeLeft == SHORT_DURATION)
49 55
                         {
50 56
                             //the auction probably expired
51 57
                             expiredAuctions.Add(a);
@@ -61,14 +67,13 @@ namespace AuctionTracker
61 67
                 if(!removedFound)
62 68
                 {
63 69
                     _logger.Info("No Expired/Sold Auctions found");
64
-                    Console.WriteLine("No Expired/Sold Auctions found");
65 70
                 }
66 71
                 if(expiredAuctions.Any())
67 72
                 {
68 73
                     StringBuilder sb = new StringBuilder();
69 74
                     foreach(Auction a in expiredAuctions)
70 75
                     {
71
-                        string name = (await _client.GetItemInfoAsync(a.Item, "en_GB")).Name;
76
+                        string name = (await _client.GetItemInfoAsync(a.Item, _locale)).Name;
72 77
                         sb.AppendLine($"{a.quantity}x {name}");
73 78
                     }
74 79
                     await _pushClient.SendNotification($"Your Auctions have expired:\n{sb.ToString()}", "none");
@@ -88,6 +93,9 @@ namespace AuctionTracker
88 93
                 .SetBasePath(Directory.GetCurrentDirectory())
89 94
                 .AddJsonFile("appsettings.json");
90 95
             _configuration = builder.Build();
96
+            _character = _configuration["character"];
97
+            _locale = _configuration["locale"];
98
+            _realm = _configuration["realm"];
91 99
             _logger.Info("Creating Clients");
92 100
             _client = new BlizzSharpClient($"{_configuration["blizzardApiKey"]}");
93 101
             _pushClient = new PushClient($"{_configuration["pushoverSecretKey"]}", $"{_configuration["pushoverUserKey"]}");