reload currency hourly, lots more converters

This commit is contained in:
Adam R Grey 2023-04-14 22:04:25 -04:00
parent 362a8784ba
commit 7e6b369b48
4 changed files with 213 additions and 7 deletions

View File

@ -55,10 +55,17 @@ namespace silverworker_discord.Conversion
{
AddLinearPair(lp.item1, lp.item2, lp.factor);
}
loadCurrency();
Task.Run(async () => {
while(true)
{
loadCurrency();
await Task.Delay(TimeSpan.FromHours(8));
}
});
}
private static void loadCurrency()
{
Console.WriteLine("loading currency exchange data.");
if (File.Exists(currencyPath))
{
currencyConf = JsonConvert.DeserializeObject<ExchangePairs>(File.ReadAllText(currencyPath));
@ -112,7 +119,7 @@ namespace silverworker_discord.Conversion
}
else
{
return $"{String.Format("{0:0.####}", accumulator)} {normalizedDestUnit}";
return $"{String.Format("{0:G4}", accumulator)} {normalizedDestUnit}";
}
}
return "no conversion known";

View File

@ -8,7 +8,7 @@ namespace silverworker_discord.Conversion
public string disclaimer{ get; set; }
public string license{ get; set; }
public int timestamp{ get; set; }
public DateTime DateUpdated { get { return DateTime.UnixEpoch.AddSeconds(timestamp); }}
public DateTime DateUpdated { get { return DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime(); }}
public string Base{ get; set; }
public Dictionary<string, decimal> rates { get; set; }
}

View File

@ -53,8 +53,6 @@ namespace silverworker_discord
_client.Log += Log;
Console.WriteLine("token, why u null?");
Console.WriteLine(config["token"]);
await _client.LoginAsync(TokenType.Bot, config["token"]);
await _client.StartAsync();

View File

@ -1,8 +1,209 @@
{
"units":[
{
"canonical": "f",
"aliases": ["degrees fahrenheit"]
"canonical": "℉",
"aliases": [
"degrees f",
"deg f",
"degf",
"fahrenheit",
"deg fahrenheit",
"degrees fahrenheit",
"°f",
"° f",
"℉",
"f"
]
},
{
"canonical":"°C",
"aliases": [
"degrees c",
"deg c",
"degc",
"celsius",
"deg celsiu",
"degrees celsiu",
"°c",
"° c",
"c"
]
},
{
"canonical":"m",
"aliases": [
"meter",
"metre"
]
},
{
"canonical":"km",
"aliases": [
"kilometer",
"kilometre"
]
},
{
"canonical":"kg",
"aliases": [
"kilogram",
"kilo"
]
},
{
"canonical":"g",
"aliases": [
"gram"
]
},
{
"canonical":"lb",
"aliases": [
"pound"
]
},
{
"canonical":"oz",
"aliases": [
"ounce"
]
},
{
"canonical":"floz",
"aliases": [
"us fl oz",
"us fl ounce",
"us fluid ounce",
"us fluid oz"
]
},
{
"canonical":"mL",
"aliases": [
"ml",
"milliletre",
"millileter"
]
},
{
"canonical":"ft",
"aliases": [
"'",
"feet",
"foot"
]
},
{
"canonical":"in",
"aliases": [
"\"",
"inch"
]
},
{
"canonical":"yd",
"aliases": [
"yard"
]
},
{
"canonical":"hhd",
"aliases": [
"hogshead"
]
},
{
"canonical":"gal",
"aliases": [
"gallon"
]
},
{
"canonical":"tbsp",
"aliases": [
"tablespoon",
"table spoon"
]
},
{
"canonical":"tsp",
"aliases": [
"teaspoon",
"tea spoon"
]
},
{
"canonical":"qt",
"aliases": [
"quart"
]
},
{
"canonical":"ac",
"aliases": [
"acres"
]
},
{
"canonical":"AU",
"aliases": [
"au",
"astronomical unit"
]
},
{
"canonical":"Pa",
"aliases": [
"pascal",
"pa"
]
},
{
"canonical":"kPa",
"aliases": [
"kilopascal",
"kpa"
]
},
{
"canonical":"atm",
"aliases": [
"atmosphere"
]
},
{
"canonical":"m^2",
"aliases": [
"square meter",
"meter squared",
"meters squared",
"sq meter",
"sq m",
"sqm"
]
},
{
"canonical":"km^2",
"aliases": [
"square kilometer",
"kilometer squared",
"kilometers squared",
"sq kilometer",
"sq km",
"sqkm"
]
},
{
"canonical":"ly",
"aliases": [
"light year"
]
},
{
"canonical":"pc",
"aliases": [
"parsec"
]
}
],
"linearPairs":[