diff --git a/Listing.cs b/Listing.cs index efa3bb8..f53b4d2 100644 --- a/Listing.cs +++ b/Listing.cs @@ -18,16 +18,31 @@ namespace Buypeeb { } } + // any items with a getter will be saved to userdata.json + // anything that's configurable by the user, such as the custom name, should be saved + // the id *must* be saved! + // i'm also saving the original name to make it easier to tell what the items are in the userdata.json + // there's not really a need for it i guess but it's my program and i can do what i want public string id { get; set; } public string name { get; set; } public int price = 0; public int winPrice; - public string originalName; + public string originalName { get; set; } public bool favourite { get; set; } = false; - // start_date, end_date + public DateTime startDate; + public DateTime endDate; + public DateTime lastUpdated; public int bids; public bool autoExtension; public bool ready; + public bool available; + + public bool updatedRecently { + get { + var later = this.lastUpdated.AddSeconds(15); + return DateTime.Compare(later, this.lastUpdated) < 0; + } + } private bool success { get; set; } // TODO: custom setter that throws an exception if set to false or something idk @@ -42,6 +57,7 @@ namespace Buypeeb { } public void Update(string html) { + // TODO: handle all the parsing errors and weird interpretation that could possibly happen here var rx = new Regex(@"var pageData ?= ?(\{.+?\});", RegexOptions.Singleline); // TODO: maybe compile and match the regex in another thread var m = rx.Match(html); if (m == null) { @@ -55,11 +71,20 @@ namespace Buypeeb { j_full = JsonSerializer.Deserialize>>(m.Groups[1].Value); } catch (Exception e) { + Console.WriteLine("oh jeez oh man oh jeez oh man oh jeez oh man"); + Console.WriteLine(m.Groups[1].Value); throw e; } + var jst = TimeZoneInfo.FindSystemTimeZoneById("Asia/Tokyo"); + var j = j_full["items"]; this.originalName = j["productName"]; + this.startDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.ParseExact(j["starttime"], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), jst); + this.endDate = TimeZoneInfo.ConvertTimeToUtc(DateTime.ParseExact(j["endtime"], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), jst); + this.lastUpdated = DateTime.UtcNow; + this.available = j["isClosed"] == "0"; + this.success = int.TryParse(j["price"], out this.price); this.success = int.TryParse(j["winPrice"], out this.winPrice); this.success = int.TryParse(j["bids"], out this.bids); diff --git a/MainWindow.cs b/MainWindow.cs index dae84f8..241fd39 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -200,10 +200,14 @@ namespace Buypeeb { Console.WriteLine($"{id} updated."); } - private void UpdateItem(string id) { + private void UpdateItem(string id, bool force = false) { // don't start a new task if there are more than [tasklimit] tasks currently running // this makes sure we don't make 1000 simultaneous requests to yahoo auctions if there are 1000 items on the watchlist - this.settings.watchlist[id].ready = false; + if (this.settings.watchlist[id].updatedRecently && !force) { + // the item has been updated recently, and force is not true + return; + } + taskLimit.Wait(); var t = Task.Factory.StartNew(() => { this.UpdateThread(id); @@ -433,7 +437,22 @@ namespace Buypeeb { private void RenderColumnEnding(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) { YahooAuctionsItem item = (YahooAuctionsItem)model.GetValue(iter, 0); - (cell as Gtk.CellRendererText).Text = item.ready ? "whatever" : "..."; + string ending = ""; + if (item.ready) { + var now = DateTime.Now; + var end = item.endDate.ToLocalTime(); + // TODO: should we show the year if the auction ends next year? 0uo + if (end.DayOfYear != now.DayOfYear) { + // the auction isn't ending today, so we should show the day it's ending on for clarity + ending += end.ToString("MMM d "); + } + ending += end.ToString("HH:mm"); + if (this.settings.displaySecondsInList) { + // add the seconds on to the end + ending += end.ToString(":ss"); + } + } + (cell as Gtk.CellRendererText).Text = item.ready ? ending : "..."; } } diff --git a/Settings.cs b/Settings.cs index 5bb0b50..1772f76 100644 --- a/Settings.cs +++ b/Settings.cs @@ -8,6 +8,7 @@ namespace Buypeeb { public int favouriteUpdateInterval { get; set; } = 5 * 60; public int updateIntervalCritical { get; set; } = 60; public int favouriteUpdateIntervalCritical { get; set; } = 30; + public bool displaySecondsInList { get; set; } = true; public Dictionary watchlist { get; set;