actually handle date/time stuff properly
This commit is contained in:
parent
ee947c84a0
commit
f252b52553
3 changed files with 50 additions and 5 deletions
29
Listing.cs
29
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 id { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public int price = 0;
|
public int price = 0;
|
||||||
public int winPrice;
|
public int winPrice;
|
||||||
public string originalName;
|
public string originalName { get; set; }
|
||||||
public bool favourite { get; set; } = false;
|
public bool favourite { get; set; } = false;
|
||||||
// start_date, end_date
|
public DateTime startDate;
|
||||||
|
public DateTime endDate;
|
||||||
|
public DateTime lastUpdated;
|
||||||
public int bids;
|
public int bids;
|
||||||
public bool autoExtension;
|
public bool autoExtension;
|
||||||
public bool ready;
|
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
|
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) {
|
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 rx = new Regex(@"var pageData ?= ?(\{.+?\});", RegexOptions.Singleline); // TODO: maybe compile and match the regex in another thread
|
||||||
var m = rx.Match(html);
|
var m = rx.Match(html);
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
|
@ -55,11 +71,20 @@ namespace Buypeeb {
|
||||||
j_full = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(m.Groups[1].Value);
|
j_full = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(m.Groups[1].Value);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
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;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var jst = TimeZoneInfo.FindSystemTimeZoneById("Asia/Tokyo");
|
||||||
|
|
||||||
var j = j_full["items"];
|
var j = j_full["items"];
|
||||||
this.originalName = j["productName"];
|
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["price"], out this.price);
|
||||||
this.success = int.TryParse(j["winPrice"], out this.winPrice);
|
this.success = int.TryParse(j["winPrice"], out this.winPrice);
|
||||||
this.success = int.TryParse(j["bids"], out this.bids);
|
this.success = int.TryParse(j["bids"], out this.bids);
|
||||||
|
|
|
@ -200,10 +200,14 @@ namespace Buypeeb {
|
||||||
Console.WriteLine($"{id} updated.");
|
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
|
// 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 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();
|
taskLimit.Wait();
|
||||||
var t = Task.Factory.StartNew(() => {
|
var t = Task.Factory.StartNew(() => {
|
||||||
this.UpdateThread(id);
|
this.UpdateThread(id);
|
||||||
|
@ -433,7 +437,22 @@ namespace Buypeeb {
|
||||||
|
|
||||||
private void RenderColumnEnding(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
private void RenderColumnEnding(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
||||||
YahooAuctionsItem item = (YahooAuctionsItem)model.GetValue(iter, 0);
|
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 : "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ namespace Buypeeb {
|
||||||
public int favouriteUpdateInterval { get; set; } = 5 * 60;
|
public int favouriteUpdateInterval { get; set; } = 5 * 60;
|
||||||
public int updateIntervalCritical { get; set; } = 60;
|
public int updateIntervalCritical { get; set; } = 60;
|
||||||
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
||||||
|
public bool displaySecondsInList { get; set; } = true;
|
||||||
|
|
||||||
public Dictionary<string, YahooAuctionsItem> watchlist {
|
public Dictionary<string, YahooAuctionsItem> watchlist {
|
||||||
get; set;
|
get; set;
|
||||||
|
|
Loading…
Reference in a new issue