Compare commits
2 commits
8d447109ad
...
562b1330c9
Author | SHA1 | Date | |
---|---|---|---|
562b1330c9 | |||
80488d7c71 |
4 changed files with 76 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using Gtk;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Buypeeb {
|
||||
class BuypeebApp {
|
||||
|
@ -16,5 +17,16 @@ 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;
|
||||
public string id;
|
||||
public string name;
|
||||
public string url { get; set; }
|
||||
public string id { get; set; }
|
||||
public string name { get; set; }
|
||||
public int price;
|
||||
public int win_price;
|
||||
public string original_name;
|
||||
public bool favourite;
|
||||
public bool favourite { get; set; } = false;
|
||||
// start_date, end_date
|
||||
public int bids;
|
||||
public bool auto_extension;
|
||||
|
|
|
@ -32,22 +32,19 @@ 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 = new Settings();
|
||||
this.settings.Save();
|
||||
this.Title = "Buypeeb";
|
||||
builder.Autoconnect(this);
|
||||
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) {
|
||||
this.items = (ListStore)builder.GetObject("ListItems");
|
||||
this.RenderList();
|
||||
foreach (object[] row in this.items) {
|
||||
Console.WriteLine(row[(int)ItemColumns.Name]);
|
||||
}
|
||||
DeleteEvent += Window_Shutdown;
|
||||
|
@ -82,6 +79,14 @@ 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) {
|
||||
|
@ -96,6 +101,8 @@ 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,14 +1,53 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Buypeeb {
|
||||
|
||||
class Settings {
|
||||
public Dictionary<string, Listing> watchlist;
|
||||
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 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>();
|
||||
string id = "k12345";
|
||||
this.watchlist.Add(id, new Listing("https://yahoo.jp", id, "my thingy"));
|
||||
this.watchlist[id].Update();
|
||||
this.Watch("https://buypeeb.biz/whatever/k12345", "my thingy");
|
||||
this.watchlist["k12345"].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