Skip to content

Instantly share code, notes, and snippets.

@UtaVile
Created February 15, 2022 11:33
Show Gist options
  • Save UtaVile/f0e2003c40df7592ccefbfe8de339b16 to your computer and use it in GitHub Desktop.
Save UtaVile/f0e2003c40df7592ccefbfe8de339b16 to your computer and use it in GitHub Desktop.
// ## ## ######## #### ## ######
// ## ## ## ## ## ## ##
// ## ## ## ## ## ##
// ## ## ## ## ## ######
// ## ## ## ## ## ##
// ## ## ## ## ## ## ##
// ####### ## #### ######## ######
// https://stackoverflow.com/questions/17781472/how-to-get-a-subset-of-a-javascript-objects-properties courtesy of Brett Zamir
// pick(obj,'a','b') looks better than (({ a, b }) => ({ a, b }))(obj);
const pick = (o, ...p) => eval(`(({${(p.a = p.join(","))}})=>({${p.a}}))(o)`);
console.log("ᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐᗐ");
// const fs = require("fs");
// const scryfall = require("scryfall-client");
// ###### ######## ######## ######
// ## ## ## ## ## ##
// ## ## ## ##
// ###### ###### ## ######
// ## ## ## ##
// ## ## ## ## ## ##
// ###### ######## ## ######
// let fullSets = {};
// try {
// if (fs.existsSync(__dirname + "/data/mtg/SETS.json")) {
// fullSets = require(__dirname + "/data/mtg/SETS.json");
// } else {
// const ORACLE = require(__dirname + "/data/mtg/oracle-cards-20220208.json");
// let mtgSetsRet = [...new Set(ORACLE.map((item) => item.set))]; //get Set of unique mtgsets
// mtgSetsRet = mtgSetsRet.reduce((acc, curr) => ((acc[curr] = ""), acc), {}); // turn the array into object keys
// // console.log(UNIQUE);
// ORACLE.forEach((card) => {
// if (Reflect.has(mtgSetsRet, card.set) && mtgSetsRet[card.set] == "") {
// // let tempy = card;
// mtgSetsRet[card.set] = (({ set, set_name }) => ({ set, set_name }))(
// card
// );
// }
// // if (UNIQUE[card.set] === "7ed") console.log("here");
// });
// console.dir(mtgSetsRet);
// // fs.writeFile(
// // __dirname + "/data/mtg/SETS.json",
// // JSON.stringify(UNIQUE),
// // "utf8",
// // () => {}
// // );
// // console.dir(UNIQUE);
// }
// } catch (err) {
// console.error(err);
// }
const FULL_SETS = require(__dirname + "/data/mtg/sets-20220208.json").data;
let setRetData = [];
let temp;
// console.dir(FULL_SETS);
FULL_SETS.forEach((mtgSet) => {
// let alreadyHas = setRetData.filter((e) => e.Name === mtgSet.set_name).length > 0;
if (
mtgSet.card_count > 0 &&
mtgSet.set_type != "token" &&
mtgSet.set_type != "memorabilia"
) {
setRetData.push(pick(mtgSet, "released_at", "name", "code", "card_count")); // "icon_svg_uri":
}
});
console.dir(setRetData);
/////////////FILE COMMENTED OUT STARTING HERE
// try {
// if (fs.existsSync(__dirname + "/data/mtg/ALL.json")) {
// fullSets = require(__dirname + "/data/mtg/ALL.json");
// } else {
// const MTG_SETS = require(__dirname + "/data/mtg/deckmaster_sets.json");
// const ORACLE = require(__dirname + "/data/mtg/oracle-cards-20220208.json");
// // put sets ids as object keys
// for (const [key, value] of Object.entries(MTG_SETS)) {
// fullSets[value.productCode] = value;
// fullSets[value.productCode].cards = [];
// }
// ORACLE.forEach((element) => {
// if (fullSets.hasOwnProperty(element.set.toUpperCase())) {
// fullSets[element.set.toUpperCase()]["cards"].push(element);
// } else if (element.set != "n/a") {
// fullSets[element.set.toUpperCase()] = {};
// fullSets[element.set.toUpperCase()].cards = [];
// fullSets[element.set.toUpperCase()].cards.push(element);
// } else {
// }
// });
// fs.writeFile(
// __dirname + "/data/mtg/ALL.json",
// JSON.stringify(fullSets),
// "utf8",
// () => {}
// );
// console.log(JSON.stringify(ORACLE).length);
// console.log(JSON.stringify(fullSets).length);
// }
// } catch (err) {
// console.error(err);
// }
// // subset the set data to what we want to give to the browser
// let setRetData = [];
// for (const ASET in fullSets) {
// fullSets[ASET]["cardCount"] = fullSets[ASET]["cards"].length;
// delete fullSets[ASET]["cards"];
// delete fullSets[ASET]["codename"];
// if (parseInt(fullSets[ASET]["cardCount"]) > 0) {
// setRetData.push(fullSets[ASET]);
// }
// }
// // console.dir(setRetData);
// ///////////FILE COMMENTED OUT STARTING HERE
// // ###### ### ######## ######## ######
// // ## ## ## ## ## ## ## ## ## ##
// // ## ## ## ## ## ## ## ##
// // ## ## ## ######## ## ## ######
// // ## ######### ## ## ## ## ##
// // ## ## ## ## ## ## ## ## ## ##
// // ###### ## ## ## ## ######## ######
// // ## ## ######## ########
// // ## ## ## ## ## ##
// // ## ## ## ## ## ##
// // ## ## ## ###### ########
// // ## ## ## ## ## ##
// // ## ## ## ## ## ##
// // ### ### ######## ########
// var express = require("express");
// var app = express();
// var http = require("https");
// var server = require("http").Server(app);
// var io = require("socket.io")(server, {
// pingInterval: 25000,
// pingTimeout: 60000,
// // > 800KB for standard maxHttpBufferSize: 1e6
// // > 16MB for maxHttpBufferSize: 2e7 in socket.io
// maxHttpBufferSize: 2e7,
// });
// app.use("/lib", express.static("lib"));
// app.use("/fonts", express.static("fonts"));
// app.use("/node_modules", express.static("node_modules"));
// app.set("view engine", "ejs");
// app.get("/", function (req, res) {
// res.render("pages/index", {
// mtgSets: setRetData,
// });
// });
// const port = 8080;
// var serverip = 0;
// server.listen(port, function () {
// // console.log(ifs.lo[0].address + ":" + port);
// console.log(
// "http://" + require("os").networkInterfaces().wlp1s0[0].address + ":" + port
// );
// console.log("ᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑᗑ");
// });
// // // @ todo socket.io
// // var connectedPlayers = [];
// // var showeventlog = true;
// // var welcome = io.of("/welcome");
// // welcome.on("connection", function (socket) {
// // var userId = socket.id; // user/client identifier for communication
// // console.log(`${userId} just logged in.`);
// // connectedPlayers.push(userId);
// // socket.on("somethingelse", function () {
// // // do something else
// // });
// // socket.emit("seteeventlog", showeventlog);
// // socket.on("userloginattempt", function (playerid, somepassword) {});
// // });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment