version 1

This commit is contained in:
Adam R. Grey 2021-10-07 06:27:33 -04:00
parent a6e5d92d4d
commit 2450c60703
14 changed files with 479 additions and 0 deletions

8
.gitignore vendored
View File

@ -9,3 +9,11 @@
# Local History for Visual Studio Code
.history/
# ---> microsoft
bin/
obj/
# specific to us
default-now.json
oracled.json
oracle-now.json

26
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net5.0/creatureBirdDwarf.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

42
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/creatureBirdDwarf.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/creatureBirdDwarf.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/creatureBirdDwarf.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}

101
Program.cs Normal file
View File

@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Linq;
using System.Net;
using Newtonsoft.Json;
using Scryfalltypes;
using System.Threading.Tasks;
using System.Diagnostics;
namespace creatureBirdDwarf
{
class Program
{
static async Task Main(string[] args)
{
var request = WebRequest.Create("https://api.scryfall.com/bulk-data");
var response = request.GetResponse();
BulkMetaEntry oracleMeta, defaultMeta;
using (var dataStream = new StreamReader(response.GetResponseStream()))
{
string responseFromServer = dataStream.ReadToEnd();
var bulk = JsonConvert.DeserializeObject<BulkDataList>(responseFromServer);
oracleMeta = bulk.data.FirstOrDefault(d => d.type == "oracle_cards");
defaultMeta = bulk.data.FirstOrDefault(d => d.type == "default_cards");
}
Console.WriteLine("found oracle download uri");
Console.WriteLine("scryfall requests 50-100 ms between requests...");
await Task.Delay(100);
Console.WriteLine("should be good.");
request = WebRequest.Create(oracleMeta.download_uri);
response = request.GetResponse();
var OracleIDd = new List<Card>();
using (var dataStream = new StreamReader(response.GetResponseStream()))
{
string responseFromServer = dataStream.ReadToEnd();
OracleIDd = JsonConvert.DeserializeObject<List<Card>>(responseFromServer);
}
foreach (var card in OracleIDd)
{
card.prices = null;
}
Console.WriteLine("stripped price data, writing to file");
File.WriteAllText("./oracle-now.json", JsonConvert.SerializeObject(OracleIDd, Formatting.Indented));
var checksumNow = GetChecksum("./oracle-now.json");
Console.WriteLine($"oracled checksum: {checksumNow}");
if (!File.Exists("./oracled.json"))
{
File.CreateText("./oracled.json");
Console.WriteLine("no oracled.json, can't help but assume checksums will be different");
}
var checksumOlder = GetChecksum("./oracled.json");
Console.WriteLine($"previous oracled checksum: {checksumOlder}");
if (checksumOlder != checksumNow)
{
Console.WriteLine("looks different, going to have to update.");
Console.WriteLine("scryfall requests 50-100 ms between requests...");
await Task.Delay(100);
Console.WriteLine("should be good.");
File.Delete("./oracled.json");
File.Move("./oracle-now.json", "./oracled.json");
request = WebRequest.Create(defaultMeta.download_uri);
response = request.GetResponse();
var defaultList = new List<Card>();
using (var dataStream = new StreamReader(response.GetResponseStream()))
{
string responseFromServer = dataStream.ReadToEnd();
defaultList = JsonConvert.DeserializeObject<List<Card>>(responseFromServer);
File.WriteAllText("./default.json", JsonConvert.SerializeObject(defaultList, Formatting.Indented));
}
Console.WriteLine("downloaded. Git pushing.");
Process.Start("git", "add .");
Process.Start("git", "commit -m \"auto\"");
Process.Start("git", "push");
}
else
{
Console.Write("same checksum (no update)");
File.Delete("./oracle-now.json");
}
}
private static string GetChecksum(string filePath)
{
using (var stream = new BufferedStream(File.OpenRead(filePath), 1200000))
{
SHA256Managed sha = new SHA256Managed();
byte[] checksum = sha.ComputeHash(stream);
return BitConverter.ToString(checksum).Replace("-", String.Empty);
}
}
}
}

View File

@ -0,0 +1,24 @@
using System;
namespace Scryfalltypes
{
public class BulkDataList
{
public string @object { get; set; }
public string has_more { get; set; } = "";
public BulkMetaEntry[] data { get; set; }
}
public class BulkMetaEntry
{
public string @object { get; set; }
public Guid id { get; set; }
public string type { get; set; }
public DateTime updated_at { get; set; }
public Uri uri { get; set; }
public string name { get; set; }
public string description { get; set; }
public int compressed_size { get; set; }
public Uri download_uri { get; set; }
public string content_type { get; set; }
public string content_encoding { get; set; }
}
}

94
ScryfallTypes/Card.cs Normal file
View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
namespace Scryfalltypes
{
using UUID = System.String;
using Colors = IEnumerable<Color>;
public class Card
{
public int? arena_id; //This cards Arena ID, if any. A large percentage of cards are not available on Arena and do not have this ID.
public UUID id; //A unique ID for this card in Scryfalls database.
public string lang; //A language code for this printing.
public int? mtgo_id; //This cards Magic Online ID (also known as the Catalog ID), if any. A large percentage of cards are not available on Magic Online and do not have this ID.
public int? mtgo_foil_id; //This cards foil Magic Online ID (also known as the Catalog ID), if any. A large percentage of cards are not available on Magic Online and do not have this ID.
public IEnumerable<int> multiverse_ids; //This cards multiverse IDs on Gatherer, if any, as an array of integers. Note that Scryfall includes many promo cards, tokens, and other esoteric objects that do not have these identifiers.
public int? tcgplayer_id; //This cards ID on TCGplayers API, also known as the productId.
public int? tcgplayer_etched_id; //This cards ID on TCGplayers API, for its etched version if that version is a separate product.
public int? cardmarket_id; //This cards ID on Cardmarkets API, also known as the idProduct.
public string @object; //A content type for this object, always card.
public UUID oracle_id; //A unique ID for this cards oracle identity. This value is consistent across reprinted card editions, and unique among different cards with the same name (tokens, Unstable variants, etc).
public Uri prints_search_uri; //A link to where you can begin paginating all re/prints for this card on Scryfalls API.
public Uri rulings_uri; //A link to this cards rulings list on Scryfalls API.
public Uri scryfall_uri; //A link to this cards permapage on Scryfalls website.
public Uri uri; //A link to this card object on Scryfalls API.
#region gameplay
public IEnumerable<RelatedCard> all_parts; //If this card is closely related to other cards, this property will be an array with Related Card Objects.
public IEnumerable<CardFace> card_faces; //An array of Card Face objects, if this card is multifaced.
public Decimal cmc; //The cards converted mana cost. Note that some funny cards have fractional mana costs.
public Colors color_identity; //This cards color identity.
public Colors color_indicator; //The colors in this cards color indicator, if any. A null value for this field indicates the card does not have one.
public Colors colors; //This cards colors, if the overall card has colors defined by the rules. Otherwise the colors will be on the card_faces objects, see below.
public int? edhrec_rank; //This cards overall rank/popularity on EDHREC. Not all cards are ranked.
public string hand_modifier; //This cards hand modifier, if it is Vanguard card. This value will contain a delta, such as -1.
public IEnumerable<string> keywords; //An array of keywords that this card uses, such as 'Flying' and 'Cumulative upkeep'.
public string layout; //A code for this cards layout.
public Legalities legalities; //An object describing the legality of this card across play formats. Possible legalities are legal, not_legal, restricted, and banned.
public string life_modifier; //This cards life modifier, if it is Vanguard card. This value will contain a delta, such as +2.
public string loyalty; //This loyalty if any. Note that some cards have loyalties that are not numeric, such as X.
public string mana_cost; //The mana cost for this card. This value will be any empty string "" if the cost is absent. Remember that per the game rules, a missing mana cost and a mana cost of {0} are different values. Multi-faced cards will report this value in card faces.
public string name; //The name of this card. If this card has multiple faces, this field will contain both names separated by ␣//␣.
public string oracle_text; //The Oracle text for this card, if any.
public bool oversized; //True if this card is oversized.
public string power; //This cards power, if any. Note that some cards have powers that are not numeric, such as *.
public Colors produced_mana; //Colors of mana that this card could produce.
public bool reserved; //True if this card is on the Reserved List.
public string toughness; //This cards toughness, if any. Note that some cards have toughnesses that are not numeric, such as *.
public string type_line; //The type line of this card.
#endregion
#region print
public string artist; //The name of the illustrator of this card. Newly spoiled cards may not have this field yet.
public bool booster; //Whether this card is found in boosters.
public string border_color; //This cards border color: black, white, borderless, silver, or gold.
public UUID card_back_id; //The Scryfall ID for the card back design present on this card.
public string collector_number; //This cards collector number. Note that collector numbers can contain non-numeric characters, such as letters or ★.
public bool? content_warning; //True if you should consider avoiding use of this print downstream.
public bool digital; //True if this card was only released in a video game.
public IEnumerable<string> finishes; //An array of computer-readable flags that indicate if this card can come in foil, nonfoil, etched, or glossy finishes.
public string flavor_name; //The just-for-fun name printed on the card (such as for Godzilla series cards).
public string flavor_text; //The flavor text, if any.
public IEnumerable<string> frame_effects; //This cards frame effects, if any.
public string frame; //This cards frame layout.
public bool full_art; //True if this cards artwork is larger than normal.
public IEnumerable<string> games; //A list of games that this card print is available in, paper, arena, and/or mtgo.
public bool highres_image; //True if this cards imagery is high resolution.
public UUID illustration_id; //A unique identifier for the card artwork that remains consistent across reprints. Newly spoiled cards may not have this field yet.
public string image_status; //A computer-readable indicator for the state of this cards image, one of missing, placeholder, lowres, or highres_scan.
public Images image_uris; //An object listing available imagery for this card. See the Card Imagery article for more information.
public Dictionary<string, Uri> prices; //An object containing daily price information for this card, including usd, usd_foil, usd_etched, eur, and tix prices, as strings.
public string printed_name; //The localized name printed on this card, if any.
public string printed_text; //The localized text printed on this card, if any.
public string printed_type_line; //The localized type line printed on this card, if any.
public bool promo; //True if this card is a promotional print.
public IEnumerable<string> promo_types; //An array of strings describing what categories of promo cards this card falls into.
public Dictionary<string, Uri> purchase_uris; //An object providing URIs to this cards listing on major marketplaces.
public string rarity; //This cards rarity. One of common, uncommon, rare, special, mythic, or bonus.
public Dictionary<string, Uri> related_uris; //An object providing URIs to this cards listing on other Magic: The Gathering online resources.
public DateTime released_at; //The date this card was first released.
public bool reprint; //True if this card is a reprint.
public Uri scryfall_set_uri; //A link to this cards set on Scryfalls website.
public string set_name; //This cards full set name.
public Uri set_search_uri; //A link to where you can begin paginating this cards set on the Scryfall API.
public string set_type; //The type of set this printing is in.
public Uri set_uri; //A link to this cards set object on Scryfalls API.
public string set; //This cards set code.
public string set_id; //This cards Set object UUID.
public bool story_spotlight; //True if this card is a Story Spotlight.
public bool textless; //True if the card is printed without text.
public bool variation; //Whether this card is a variation of another printing.
public UUID variation_of; //The printing ID of the printing this card is a variation of.
public string watermark; //This cards watermark, if any.
public Preview preview;
#endregion
}
}

29
ScryfallTypes/CardFace.cs Normal file
View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
namespace Scryfalltypes
{
using UUID = System.String;
using Colors = IEnumerable<Color>;
public class CardFace
{
public string artist { get; set; } //The name of the illustrator of this card face. Newly spoiled cards may not have this field yet.
public Colors color_indicator { get; set; } //The colors in this faces color indicator, if any.
public Colors colors { get; set; } //This faces colors, if the game defines colors for the individual face of this card.
public string flavor_text { get; set; } //The flavor text printed on this face, if any.
public UUID illustration_id { get; set; } //A unique identifier for the card face artwork that remains consistent across reprints. Newly spoiled cards may not have this field yet.
public Images image_uris { get; set; } //An object providing URIs to imagery for this face, if this is a double-sided card. If this card is not double-sided, then the image_uris property will be part of the parent object instead.
public string loyalty { get; set; } //This faces loyalty, if any.
public string mana_cost { get; set; } //The mana cost for this face. This value will be any empty string "" if the cost is absent. Remember that per the game rules, a missing mana cost and a mana cost of {0} are different values.
public string name { get; set; } //The name of this particular face.
//public string object { get; set; } //A content type for this object, always card_face.
public string oracle_text { get; set; } //The Oracle text for this face, if any.
public string power { get; set; } //This faces power, if any. Note that some cards have powers that are not numeric, such as *.
public string printed_name { get; set; } //The localized name printed on this face, if any.
public string printed_text { get; set; } //The localized text printed on this face, if any.
public string printed_type_line { get; set; } //The localized type line printed on this face, if any.
public string toughness { get; set; } //This faces toughness, if any.
public string type_line { get; set; } //The type line of this particular face.
public string watermark { get; set; } //The watermark on this particulary card face, if any.
}
}

72
ScryfallTypes/Enums.cs Normal file
View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
namespace Scryfalltypes
{
public enum Color { W, U, G, B, R, C }
//a lot of these could potentially be enums, but
// 1: might be difficult to make into enums (frames are identified by the year they started, scryfall loves the word "object" where I would prefer the term "type")
// 2: they update often enough that I'd rather not have to recompile and re-release, how often do I even want to check the specific type
public class Known
{
public List<string> Game = new List<string>()
{
//"astral",
//"sega",
"paper",
"arena",
"mtgo"
};
public List<string> Layout = new List<string>() {
"normal", //A standard Magic card with one face
"split", //A split-faced card
"flip", //Cards that invert vertically with the flip keyword
"transform", //Double-sided cards that transform
"modal_dfc", //Double-sided cards that can be played either-side
"meld", //Cards with meld parts printed on the back
"leveler", //Cards with Level Up
"class", //Class-type enchantment cards
"saga", //Saga-type cards
"adventure", //Cards with an Adventure spell part
"planar", //Plane and Phenomenon-type cards
"scheme", //Scheme-type cards
"vanguard", //Vanguard-type cards
"token", //Token cards
"double_faced_token", //Tokens with another token printed on the back
"emblem", //Emblem cards
"augment", //Cards with Augment
"host", //Host-type cards
"art_series", //Art Series collectable double-faced cards
"double_sided" //A Magic card with two sides that are unrelated
};
public List<string> Frame = new List<string>(){
"1993", //The original Magic card frame, starting from Limited Edition Alpha.
"1997", //The updated classic frame starting from Mirage block
"2003", //The “modern” Magic card frame, introduced in Eighth Edition and Mirrodin block.
"2015", //The holofoil-stamp Magic card frame, introduced in Magic 2015.
"future" //The frame used on cards from the future (i.e., Timeshifted)
};
public List<string> FrameEffect = new List<string>(){
"legendary", //The cards have a legendary crown
"miracle", //The miracle frame effect
"nyxtouched", //The Nyx-touched frame effect
"draft", //The draft-matters frame effect
"devoid", //The Devoid frame effect
"tombstone", //The Odyssey tombstone mark
"colorshifted", //A colorshifted frame
"inverted", //The FNM-style inverted frame
"sunmoondfc", //The sun and moon transform marks
"compasslanddfc", //The compass and land transform marks
"originpwdfc", //The Origins and planeswalker transform marks
"mooneldrazidfc", //The moon and Eldrazi transform marks
"waxingandwaningmoondfc", //The waxing and waning crescent moon transform marks
"showcase", //A custom Showcase frame
"extendedart", //An extended art frame
"companion", //The cards have a companion frame
"etched", //The cards have an etched foil treatment
"snow" //The cards have the snowy frame effect
};
}
}

15
ScryfallTypes/Images.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace Scryfalltypes
{
public class Images
{
public Uri png { get; set; } // 745 × 1040, PNG, A transparent, rounded full card PNG. This is the best image to use for videos or other high-quality content.
public Uri border_crop { get; set; } //480 × 680, JPG, A full card image with the rounded corners and the majority of the border cropped off. Designed for dated contexts where rounded images cant be used.
public Uri art_crop { get; set; } //Varying resolution, JPG, A rectangular crop of the cards art only. Not guaranteed to be perfect for cards with outlier designs or strange frame arrangements
public Uri large { get; set; } //672 × 936, JPG, A large full card image
public Uri normal { get; set; } //488 × 680, JPG, A medium-sized full card image
public Uri small { get; set; } //146 × 204, JPG, A small full card image. Designed for use as thumbnail or list icon.
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
namespace Scryfalltypes
{
public enum LegalCategory { not_legal, legal, restricted, banned }
public class Legalities
{
public LegalCategory standard { get; set; }
public LegalCategory future { get; set; }
public LegalCategory historic { get; set; }
public LegalCategory gladiator { get; set; }
public LegalCategory pioneer { get; set; }
public LegalCategory modern { get; set; }
public LegalCategory legacy { get; set; }
public LegalCategory pauper { get; set; }
public LegalCategory vintage { get; set; }
public LegalCategory penny { get; set; }
public LegalCategory commander { get; set; }
public LegalCategory brawl { get; set; }
public LegalCategory historicbrawl { get; set; }
public LegalCategory paupercommander { get; set; }
public LegalCategory duel { get; set; }
public LegalCategory oldschool { get; set; }
public LegalCategory premodern { get; set; }
}
}

12
ScryfallTypes/Preview.cs Normal file
View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace Scryfalltypes
{
public class Preview
{
public DateTime previewed_at; //The date this card was previewed.
public Uri source_uri; //A link to the preview for this card.
public string source; //The name of the source that previewed this card.
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace Scryfalltypes
{
using UUID = System.String;
using Colors = IEnumerable<Color>;
public class RelatedCard
{
public UUID id { get; set; } //An unique ID for this card in Scryfalls database.
//public string object { get; set; } //A content type for this object, always related_card.
public string component { get; set; } //A field explaining what role this card plays in this relationship, one of token, meld_part, meld_result, or combo_piece.
public string name { get; set; } //The name of this particular related card.
public string type_line { get; set; } //The type line of this card.
public Uri uri { get; set; } //A URI where you can retrieve a full object describing this card on Scryfalls API.
}
}

12
creatureBirdDwarf.csproj Normal file
View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>

0
sample card.json Normal file
View File