55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Buypeeb {
|
|
|
|
class Settings {
|
|
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;
|
|
|
|
public Dictionary<string, YahooAuctionsItem> watchlist {
|
|
get; set;
|
|
}
|
|
|
|
public Settings() {
|
|
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>();
|
|
}
|
|
}
|
|
|
|
public YahooAuctionsItem Watch(string url, string name) {
|
|
string id = BuypeebApp.IDFromURL(url);
|
|
Console.WriteLine(id);
|
|
this.watchlist[id] = new YahooAuctionsItem(id, name);
|
|
return this.watchlist[id];
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
}
|
|
}
|