buypeeb-cs/Settings.cs

56 lines
1.6 KiB
C#
Raw Normal View History

2020-09-02 03:21:32 +00:00
using System;
2020-09-01 10:41:29 +00:00
using System.Collections.Generic;
namespace Buypeeb {
2020-09-02 04:12:56 +00:00
2020-09-01 10:41:29 +00:00
class Settings {
2020-09-02 04:12:56 +00:00
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 bool displaySecondsInList { get; set; } = true;
2020-09-02 04:12:56 +00:00
public Dictionary<string, YahooAuctionsItem> watchlist {
2020-09-02 04:12:56 +00:00
get; set;
}
2020-09-01 10:41:29 +00:00
public Settings() {
2020-09-03 13:47:36 +00:00
if (this.watchlist == null) {
// either this is the first time the program has been run, or there's something wrong with userdata.json
this.watchlist = new Dictionary<string, YahooAuctionsItem>();
2020-09-02 04:12:56 +00:00
}
2020-09-02 03:21:32 +00:00
}
public YahooAuctionsItem Watch(string url, string name) {
2020-09-02 03:21:32 +00:00
string id = BuypeebApp.IDFromURL(url);
Console.WriteLine(id);
this.watchlist[id] = new YahooAuctionsItem(id, name);
2020-09-04 07:23:32 +00:00
return this.watchlist[id];
2020-09-01 10:41:29 +00:00
}
2020-09-05 18:36:17 +00:00
// TRUE if the item hasn't been updated for at least interval seconds
// for example, if the interval is 10, and the item hasn't been updated since 20 seconds ago, this will be TRUE
public bool ItemNotUpdatedSinceInterval(YahooAuctionsItem item) {
int seconds = 1000;
if (item.favourite) {
if (item.endingSoon) {
seconds = this.favouriteUpdateIntervalCritical;
}
else {
seconds = this.favouriteUpdateInterval;
}
}
else {
if (item.endingSoon) {
seconds = this.updateIntervalCritical;
}
else {
seconds = this.updateInterval;
}
}
var later = item.lastUpdated.AddSeconds(seconds);
return DateTime.Compare(later, DateTime.UtcNow) < 0;
}
2020-09-01 10:41:29 +00:00
}
}