but what if i used a consistent naming scheme

This commit is contained in:
Lynne Megido 2020-09-04 19:17:59 +10:00
parent 9ad7e4f288
commit b085198c2d
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
2 changed files with 31 additions and 27 deletions

View file

@ -12,7 +12,7 @@ namespace Buypeeb {
} }
} }
public string buyee_url { public string buyeeUrl {
get { get {
return $"https://buyee.jp/item/yahoo/auction/{this.id}"; return $"https://buyee.jp/item/yahoo/auction/{this.id}";
} }
@ -21,12 +21,12 @@ namespace Buypeeb {
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 win_price; public int winPrice;
public string original_name; public string originalName;
public bool favourite { get; set; } = false; public bool favourite { get; set; } = false;
// start_date, end_date // start_date, end_date
public int bids; public int bids;
public bool auto_extension; public bool autoExtension;
public bool ready; public bool ready;
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
@ -59,13 +59,13 @@ namespace Buypeeb {
} }
var j = j_full["items"]; var j = j_full["items"];
this.original_name = j["productName"]; this.originalName = j["productName"];
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.win_price); 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);
if (String.IsNullOrWhiteSpace(this.name)) { if (String.IsNullOrWhiteSpace(this.name)) {
this.name = this.original_name; this.name = this.originalName;
} }
// as far as i can tell, neither the `pageData` nor the `conf` variables in the html seem to store whether or not the auction uses automatic extension // as far as i can tell, neither the `pageData` nor the `conf` variables in the html seem to store whether or not the auction uses automatic extension
@ -75,17 +75,17 @@ namespace Buypeeb {
var autoExtensionCheck = new Regex(@"自動延長.+\n.+>(.+)<"); var autoExtensionCheck = new Regex(@"自動延長.+\n.+>(.+)<");
m = rx.Match(html); m = rx.Match(html);
if (m.Groups[1].Value != null) { if (m.Groups[1].Value != null) {
this.auto_extension = (m.Groups[1].Value == "あり"); this.autoExtension = (m.Groups[1].Value == "あり");
} }
} }
public string PriceAUD(bool win = false) { public string PriceAUD(bool win = false) {
double aud = win ? this.win_price / 75.0 : this.price / 75.0; double aud = win ? this.winPrice / 75.0 : this.price / 75.0;
return $"${aud:f2}"; return $"${aud:f2}";
} }
public string PriceJPY(bool win = false) { public string PriceJPY(bool win = false) {
return win ? $"¥{this.win_price}" : $"¥{this.price}"; return win ? $"¥{this.winPrice}" : $"¥{this.price}";
} }
} }
} }

View file

@ -50,10 +50,15 @@ namespace Buypeeb {
// TODO: whenever we get something from the builder, cache it for later // TODO: whenever we get something from the builder, cache it for later
// that way we don't need to constantly do "builder.GetObject"s // that way we don't need to constantly do "builder.GetObject"s
static SemaphoreSlim tasklimit = new SemaphoreSlim(4); static SemaphoreSlim taskLimit = new SemaphoreSlim(4);
private YahooAuctionsItem SelectedItem { private YahooAuctionsItem selectedItem {
get { get {
if (this.itemTreeView.Selection.CountSelectedRows() == 0) {
// avoids incurring the wrath of Gtk-CRITICAL **
return null;
}
this.itemTreeView.Selection.GetSelected(out TreeIter iter); this.itemTreeView.Selection.GetSelected(out TreeIter iter);
return (YahooAuctionsItem)this.itemTreeView.Model.GetValue(iter, 0); return (YahooAuctionsItem)this.itemTreeView.Model.GetValue(iter, 0);
} }
@ -116,10 +121,10 @@ namespace Buypeeb {
this.UpdateItems(); this.UpdateItems();
DeleteEvent += Window_Shutdown; DeleteEvent += WindowShutdown;
} }
private void Window_Shutdown(object sender, DeleteEventArgs args) { private void WindowShutdown(object sender, DeleteEventArgs args) {
SaveSettings(); SaveSettings();
Application.Quit(); Application.Quit();
} }
@ -184,7 +189,7 @@ namespace Buypeeb {
Gtk.Application.Invoke(delegate { Gtk.Application.Invoke(delegate {
var pathAndIter = this.GetRow(id); var pathAndIter = this.GetRow(id);
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter); this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
if (item == this.SelectedItem) { if (item == this.selectedItem) {
// if the user has this item selected and it just became ready, enable the selection box // if the user has this item selected and it just became ready, enable the selection box
var s = (Box)this.builder.GetObject("SelectionViewBox"); var s = (Box)this.builder.GetObject("SelectionViewBox");
s.Sensitive = true; s.Sensitive = true;
@ -199,10 +204,10 @@ namespace Buypeeb {
// 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; this.settings.watchlist[id].ready = false;
tasklimit.Wait(); taskLimit.Wait();
var t = Task.Factory.StartNew(() => { var t = Task.Factory.StartNew(() => {
this.UpdateThread(id); this.UpdateThread(id);
}).ContinueWith(task => { tasklimit.Release(); }); }).ContinueWith(task => { taskLimit.Release(); });
} }
private void UpdateItems() { private void UpdateItems() {
@ -219,11 +224,10 @@ namespace Buypeeb {
private void UpdateSelectionView() { private void UpdateSelectionView() {
// get the currently selected item // get the currently selected item
var item = this.SelectedItem; var item = this.selectedItem;
var s = (Box)this.builder.GetObject("SelectionViewBox"); var s = (Box)this.builder.GetObject("SelectionViewBox");
var infobox = (Box)this.builder.GetObject("SelectionInfoBox"); var infobox = (Box)this.builder.GetObject("SelectionInfoBox");
if (item == null) { if (item == null) {
s.Sensitive = false; s.Sensitive = false;
infobox.Visible = false; infobox.Visible = false;
@ -237,13 +241,13 @@ namespace Buypeeb {
var info = new Dictionary<string, string>(); var info = new Dictionary<string, string>();
info.Add("Name", item.name); info.Add("Name", item.name);
info.Add("YahooName", item.original_name); info.Add("YahooName", item.originalName);
info.Add("Price", item.PriceJPY()); info.Add("Price", item.PriceJPY());
info.Add("PriceAUD", item.PriceAUD()); info.Add("PriceAUD", item.PriceAUD());
info.Add("Ending", "whenever"); info.Add("Ending", "whenever");
info.Add("Bids", $"{item.bids}"); info.Add("Bids", $"{item.bids}");
info.Add("BuyItNow", item.win_price == 0 ? "No" : $"¥{item.PriceJPY(true)} (${item.PriceAUD(true)})"); info.Add("BuyItNow", item.winPrice == 0 ? "No" : $"¥{item.PriceJPY(true)} (${item.PriceAUD(true)})");
info.Add("AutoExtension", item.auto_extension ? "Yes" : "No"); info.Add("AutoExtension", item.autoExtension ? "Yes" : "No");
info.Add("LastUpdated", "Last updated: heeeenlo"); info.Add("LastUpdated", "Last updated: heeeenlo");
foreach (var row in info) { foreach (var row in info) {
@ -375,15 +379,15 @@ namespace Buypeeb {
} }
private void ButtonViewBuyeeClicked(object sender, EventArgs a) { private void ButtonViewBuyeeClicked(object sender, EventArgs a) {
this.OpenUrl(this.SelectedItem.buyee_url); this.OpenUrl(this.selectedItem.buyeeUrl);
} }
private void ButtonViewYahooClicked(object sender, EventArgs a) { private void ButtonViewYahooClicked(object sender, EventArgs a) {
this.OpenUrl(this.SelectedItem.url); this.OpenUrl(this.selectedItem.url);
} }
private void ButtonSelectedRemoveClicked(object sender, EventArgs a) { private void ButtonSelectedRemoveClicked(object sender, EventArgs a) {
var item = this.SelectedItem; var item = this.selectedItem;
var md = this.OkCancelDialogue($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line var md = this.OkCancelDialogue($"Are you sure you want to remove the item \"{item.name}\"?"); // TODO: this looks bad being all on one line
@ -396,7 +400,7 @@ namespace Buypeeb {
} }
private void ButtonSelectedRenameClicked(object sender, EventArgs a) { private void ButtonSelectedRenameClicked(object sender, EventArgs a) {
var item = this.SelectedItem; var item = this.selectedItem;
(bool accepted, string response) = this.EntryDialogue("Rename item", $"Enter a new name for the item \"{item.name}\".", item.name); (bool accepted, string response) = this.EntryDialogue("Rename item", $"Enter a new name for the item \"{item.name}\".", item.name);
if (accepted) { if (accepted) {
item.name = response; item.name = response;
@ -407,7 +411,7 @@ namespace Buypeeb {
private void ButtonSelectedUpdateClicked(object sender, EventArgs args) { private void ButtonSelectedUpdateClicked(object sender, EventArgs args) {
var s = (Box)this.builder.GetObject("SelectionViewBox"); var s = (Box)this.builder.GetObject("SelectionViewBox");
s.Sensitive = false; s.Sensitive = false;
this.UpdateItem(this.SelectedItem.id); this.UpdateItem(this.selectedItem.id);
} }
// column renderers // column renderers