Compare commits
No commits in common. "562b1330c96eb99c992bf03f1a10ece800318b6a" and "8d447109ad9e2926a1105a8b31eabe0970288d8b" have entirely different histories.
562b1330c9
...
8d447109ad
4 changed files with 18 additions and 76 deletions
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using Gtk;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Buypeeb {
|
||||
class BuypeebApp {
|
||||
|
@ -17,16 +16,5 @@ namespace Buypeeb {
|
|||
win.Show();
|
||||
Application.Run();
|
||||
}
|
||||
|
||||
public static string IDFromURL(string url) {
|
||||
// TODO: handle invalid URLs better, or at all really
|
||||
Regex rx = new Regex(@"^([^?]+)");
|
||||
url = rx.Match(url).Groups[1].Value; // remove query params (if any)
|
||||
|
||||
rx = new Regex(@".+\/(.+?)/?$");
|
||||
string id = rx.Match(url).Groups[1].Value; // extracts "k12345" from "https://buypeeb.biz/whatever/k12345/"
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ using System.Globalization;
|
|||
|
||||
namespace Buypeeb {
|
||||
class Listing {
|
||||
public string url { get; set; }
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string url;
|
||||
public string id;
|
||||
public string name;
|
||||
public int price;
|
||||
public int win_price;
|
||||
public string original_name;
|
||||
public bool favourite { get; set; } = false;
|
||||
public bool favourite;
|
||||
// start_date, end_date
|
||||
public int bids;
|
||||
public bool auto_extension;
|
||||
|
|
|
@ -32,19 +32,22 @@ namespace Buypeeb {
|
|||
|
||||
class MainWindow : Window {
|
||||
|
||||
private ListStore items;
|
||||
private Settings settings;
|
||||
private ListStore Items;
|
||||
private Settings Settings;
|
||||
|
||||
public MainWindow() : this(new Builder("main.glade")) { }
|
||||
|
||||
private MainWindow(Builder builder) : base(builder.GetObject("wndMain").Handle) {
|
||||
this.settings = new Settings();
|
||||
this.settings.Save();
|
||||
this.Settings = new Settings();
|
||||
this.Title = "Buypeeb";
|
||||
builder.Autoconnect(this);
|
||||
this.items = (ListStore)builder.GetObject("ListItems");
|
||||
this.RenderList();
|
||||
foreach (object[] row in this.items) {
|
||||
this.Items = (ListStore)builder.GetObject("ListItems");
|
||||
this.Items.Clear();
|
||||
foreach (KeyValuePair<string, Listing> entry in Settings.watchlist) {
|
||||
string[] values = new[] { entry.Value.name, entry.Value.PriceJPY(), entry.Value.PriceAUD(), "whenever", entry.Value.id };
|
||||
this.Items.AppendValues(values);
|
||||
}
|
||||
foreach (object[] row in this.Items) {
|
||||
Console.WriteLine(row[(int)ItemColumns.Name]);
|
||||
}
|
||||
DeleteEvent += Window_Shutdown;
|
||||
|
@ -79,14 +82,6 @@ namespace Buypeeb {
|
|||
|
||||
}
|
||||
|
||||
private void RenderList() {
|
||||
this.items.Clear();
|
||||
foreach (KeyValuePair<string, Listing> entry in settings.watchlist) {
|
||||
string[] values = new[] { entry.Value.name, entry.Value.PriceJPY(), entry.Value.PriceAUD(), "whenever", entry.Value.id };
|
||||
this.items.AppendValues(values);
|
||||
}
|
||||
}
|
||||
|
||||
// button handlers
|
||||
|
||||
private void ButtonAddClicked(object sender, EventArgs a) {
|
||||
|
@ -101,8 +96,6 @@ namespace Buypeeb {
|
|||
Regex rx = new Regex(@"^http.+yahoo.+");
|
||||
if (rx.IsMatch(url)) {
|
||||
Console.WriteLine("{0} will be added", url);
|
||||
this.settings.Watch(url, name);
|
||||
this.RenderList();
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("{0} is an invalid url", url);
|
||||
|
|
47
Settings.cs
47
Settings.cs
|
@ -1,53 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Buypeeb {
|
||||
|
||||
class Settings {
|
||||
private string location;
|
||||
|
||||
public int updateInterval { get; set; } = 10 * 60;
|
||||
public int favouriteUpdateInterval { get; set; } = 5 * 60;
|
||||
public int updateIntervalCritical { get; set; } = 60;
|
||||
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
||||
|
||||
public Dictionary<string, Listing> watchlist {
|
||||
get; set;
|
||||
}
|
||||
public Dictionary<string, Listing> watchlist;
|
||||
|
||||
public Settings() {
|
||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
|
||||
// C:\Users\Beebus\AppData\Roaming\Lynnear Software\buypeeb
|
||||
this.location = Path.Combine(Environment.ExpandEnvironmentVariables("%APPDATA%"), "Lynnear Software", "buypeeb");
|
||||
}
|
||||
else {
|
||||
// ~/.config/Lynnear Software/buypeeb
|
||||
this.location = Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".config", "Lynnear Software", "buypeeb");
|
||||
}
|
||||
this.watchlist = new Dictionary<string, Listing>();
|
||||
this.Watch("https://buypeeb.biz/whatever/k12345", "my thingy");
|
||||
this.watchlist["k12345"].Update();
|
||||
string id = "k12345";
|
||||
this.watchlist.Add(id, new Listing("https://yahoo.jp", id, "my thingy"));
|
||||
this.watchlist[id].Update();
|
||||
}
|
||||
|
||||
public void Watch(string url, string name) {
|
||||
string id = BuypeebApp.IDFromURL(url);
|
||||
Console.WriteLine(id);
|
||||
this.watchlist[id] = new Listing(url, id, name);
|
||||
|
||||
foreach (KeyValuePair<string, Listing> entry in this.watchlist) {
|
||||
Console.WriteLine("{0} - {1}", entry.Value.name, entry.Value.price);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save() {
|
||||
string j = JsonSerializer.Serialize(this);
|
||||
Console.WriteLine(j);
|
||||
}
|
||||
|
||||
// public void Load() {
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue