Vredeza / bimf

Unofficial Moxfield tool to import multiple cards from a single MTG set.
https://vredeza.github.io/bimf/
Apache License 2.0
0 stars 0 forks source link

adding txt-file export #1

Open henritielscher opened 4 months ago

henritielscher commented 4 months ago

Hey there, first of all. Awesome tool! For my purpose it would be absolutely great to have a txt-file export as well, since I track all drafts via decks, which I then add to the collection. Unfortunately the deck builder on moxfield does not support importing csv-files. I'm programming myself, mostly in React / Typescript, if you need any help implementing that... Best, Henri

henritielscher commented 4 months ago

I've written some small script which worked out:

import fs from "fs";
import csvParser from "csv-parser";

type TextObject = {
    Count: string;
    Name: string;
    Edition: string;
    "Collector Number": string;
    Foil?: string;
};

let text: TextObject[] = [];

fs.createReadStream("./data.csv")
    .pipe(csvParser())
    .on("data", (data) => {
        text.push(data);
    })
    .on("close", () => {
        text.forEach((object) => {
            const {
                "Collector Number": Number,
                Count,
                Edition,
                Name,
                Foil,
            } = object;

            console.log(
                `${Count} ${Name} (${Edition.toUpperCase()}) ${Number} ${
                    Foil ? "*F*" : ""
                }`
            );
        });
    });
henritielscher commented 4 months ago

Sorry forgot to mention, that I used your CSV to transfer it back to text. I think doing a text download button should be a piece of cake using your Dataset and the logic of DownloadButton.js to simply put out a blob as txt file separating by lines. Thanks again. I already saved so much time :D