smarter compare.
if one list has something with an oracle id the other doesn't, that means a card was added or removed, update. if the oracle text is updated, update. otherwise, don't.
This commit is contained in:
parent
2630cf799e
commit
10face4c9e
48
Program.cs
48
Program.cs
@ -39,26 +39,19 @@ namespace creatureBirdDwarf
|
|||||||
string responseFromServer = dataStream.ReadToEnd();
|
string responseFromServer = dataStream.ReadToEnd();
|
||||||
OracleIDd = JsonConvert.DeserializeObject<List<Card>>(responseFromServer);
|
OracleIDd = JsonConvert.DeserializeObject<List<Card>>(responseFromServer);
|
||||||
}
|
}
|
||||||
stripData(ref OracleIDd);
|
|
||||||
|
|
||||||
Console.WriteLine("stripped external (price and edhrec rank) data, writing to file");
|
|
||||||
|
|
||||||
File.WriteAllText("./oracle-now.json", JsonConvert.SerializeObject(OracleIDd, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()));
|
File.WriteAllText("./oracle-now.json", JsonConvert.SerializeObject(OracleIDd, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()));
|
||||||
var checksumNow = GetChecksum("./oracle-now.json");
|
|
||||||
Console.WriteLine($"oracled checksum: {checksumNow}");
|
|
||||||
|
|
||||||
if (!File.Exists("./oracled.json"))
|
if (!File.Exists("./oracled.json"))
|
||||||
{
|
{
|
||||||
File.CreateText("./oracled.json");
|
File.CreateText("./oracled.json");
|
||||||
Console.WriteLine("no oracled.json, can't help but assume checksums will be different");
|
Console.WriteLine("no oracled.json, can't help but assume contents will be different");
|
||||||
}
|
}
|
||||||
var checksumOlder = GetChecksum("./oracled.json");
|
|
||||||
Console.WriteLine($"previous oracled checksum: {checksumOlder}");
|
|
||||||
|
|
||||||
if (checksumOlder != checksumNow)
|
if (needUpdate("./oracled.json", "./oracle-now.json"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("looks different, going to have to update.");
|
Console.WriteLine("looks different, going to have to update.");
|
||||||
Console.WriteLine("scryfall requests 50-100 ms between requests...");
|
Console.WriteLine("scryfall requests 50-100 ms between requests. Granted I can't imagine it hasn't been that long.");
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
Console.WriteLine("should be good.");
|
Console.WriteLine("should be good.");
|
||||||
File.Delete("./oracled.json");
|
File.Delete("./oracled.json");
|
||||||
@ -71,7 +64,6 @@ namespace creatureBirdDwarf
|
|||||||
{
|
{
|
||||||
string responseFromServer = dataStream.ReadToEnd();
|
string responseFromServer = dataStream.ReadToEnd();
|
||||||
defaultList = JsonConvert.DeserializeObject<List<Card>>(responseFromServer);
|
defaultList = JsonConvert.DeserializeObject<List<Card>>(responseFromServer);
|
||||||
stripData(ref defaultList);
|
|
||||||
File.WriteAllText("./default.json", JsonConvert.SerializeObject(defaultList, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()));
|
File.WriteAllText("./default.json", JsonConvert.SerializeObject(defaultList, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,23 +73,35 @@ namespace creatureBirdDwarf
|
|||||||
File.Delete("./oracle-now.json");
|
File.Delete("./oracle-now.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static bool needUpdate(string path1, string path2)
|
||||||
private static void stripData(ref List<Card> collection)
|
|
||||||
{
|
{
|
||||||
foreach (var card in collection)
|
if(File.Exists(path1) && File.Exists(path2))
|
||||||
{
|
{
|
||||||
card.prices = null;
|
var lhs = JsonConvert.DeserializeObject<List<Card>>(File.ReadAllText(path1));
|
||||||
card.edhrec_rank = null;
|
var rhs = JsonConvert.DeserializeObject<List<Card>>(File.ReadAllText(path2));
|
||||||
|
if(lhs == null || rhs == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
foreach(var lhsCard in lhs)
|
||||||
|
{
|
||||||
|
var rhsCard = rhs.FirstOrDefault(c => c.oracle_id == lhsCard.oracle_id);
|
||||||
|
if(rhsCard == null || lhsCard.oracle_text != rhsCard.oracle_text)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
rhs.Remove(rhsCard);
|
||||||
|
}
|
||||||
|
if(rhs.Count() > 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetChecksum(string filePath)
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
using (var stream = new BufferedStream(File.OpenRead(filePath), 1200000))
|
return true;
|
||||||
{
|
|
||||||
SHA256Managed sha = new SHA256Managed();
|
|
||||||
byte[] checksum = sha.ComputeHash(stream);
|
|
||||||
return BitConverter.ToString(checksum).Replace("-", String.Empty);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user