nicho92 / MtgDesktopCompanion

Cards manager for magic the gathering
Apache License 2.0
163 stars 35 forks source link

Format for importing csv files #172

Closed LoganDungeon closed 2 years ago

LoganDungeon commented 3 years ago

You should add documentation on what fields are needed for csv imports and how they should be formated.

When i try to import files from Delver Lens, nothing happens Windows gives 'Import finished' notification, but no cards show up; no error. Even when trying to import the in #75 mentioned 'export.txt' nothing happens.

Am i missing something with importing cards into the program or is this an area, where the companion still needs some work?

nicho92 commented 3 years ago

i have a simple doc for CSVwhen you click on '?' in adminPanel coul'd you send me your log file ? image

nicho92 commented 3 years ago

Did you tried DelverLens import plugin ?

LoganDungeon commented 3 years ago

I did try the DelverLens import tool and the 'normal' csv import tool. Neither seem to do the job. The log just reports no match found for any format i try.

For the delver lens tool it seems that you use regex to validate the input. I don't think this works well, since in the app, you can chose which fields to export, so in order for the regex to work, one would have to chose the exact needed fields in the exact sequence.

And for the normal csv format it seems, that as soon as some fields are missing, the import just fails.

I feel like the only fields that should be "required" are name, quantity, edition and maybe Card Number to differentiate special Editions. For everything else, you could just assume a default value, eg. for foil assume not foil if missing, for condition assume MINT, unless specified otherwise.

Maybe i am completely wrong assuming this. But as it stands now, i am quite confused on how to format my card list, so that they all import properly into the companion.

nicho92 commented 3 years ago

can you send me your import files ? or just a sample

LoganDungeon commented 3 years ago

Of course Here a Delver Lens example:

Name,Edition,Collector's number,Foil,Quantity
"Rakshasa's Secret","Khans of Tarkir","84","","2"
"Zombie Infestation","Premium Deck Series: Graveborn","19","Foil","1"

and a csv example with the needed fields:

Card Name;Edition;Language;Qte;Condition;Foil;Altered;Signed;Collection;Price;Comment
Bind the Monster;Kaldheim;English;1;MINT;true;false;false;Library;0.0;null;
Birgi, God of Storytelling;Kaldheim;English;1;MINT;false;false;false;Library;0.0;null;
nicho92 commented 3 years ago

your delver lens format is simple format. I developped plugin for "Count,Tradelist Count,Name,Edition,Card Number,Condition,Language,Foil,Signed,Artist Proof,Altered Art,Misprint,Promo,Textless,My Price"

i need to update this plugin for multiple formats.

for your CSV export you missed on column . and i see i forgot to catch names with comma. I'll fixed in next release. be carreful, by default, separator is semicolon

LoganDungeon commented 3 years ago

I managed to write a program that converts exports from Delver Lens to a format that can be imported into the MTG companion.

nicho92 commented 3 years ago

nice, do you wan't to share it ? i can adapte it to be integrated in mtgcompanion Delver plugin

LoganDungeon commented 3 years ago

So this python script converts a specific format of delver lens files to a single collection '.csv' file for the companion.
It expects any number of files in a folder called 'collection' in the same directory as the script.
It depends only on the 'pandas' libraray for dataframe manipulation.
The format for the input files should be:

Quantity, <Blank>, Name, Edition, Collector's number, Condition, Language, Foil, <Blank>, <Blank>, <Blank>, <Blank>, <Blank>, <Blank>, <Blank>

The the script will convert it to the following format:

Count,Tradelist Count,Name,Edition,Card Number,Condition,Language,Foil,Signed,Artist Proof,Altered Art,Misprint,Promo,Textless,My Price

The script does the following notable things:

  1. Rename the \ fields to the accomodate the regex
  2. Convert the foil collumn to lower case
  3. Concatenate multiple input files to one single collection file (delver lens is free, as long as you export <100 card lists)
  4. Sets Tradelist Count equal to Count (Have not used tradelist yet, maybe this should be zero)
  5. Assumes the items go in the 'Library' collection

I don't know exactly how your plugin works, but this should probably be rewritten in java with something like tablesaw As my experience with java is limited to the bit we did in university a few years back and i have not worked with big projects yet, i don't think i can be a big help in this part. But maybe this is enough for you to know how to integrate this or something similar.

import pandas as pd
import os
import csv

# Format of the input files:
# Quantity, <Blank>, Name, Edition, Collector's number, Condition, Language, Foil, <Blank>, <Blank>, <Blank>, <Blank>, <Blank>, <Blank>, <Blank>

# Output format:
# Count,Tradelist Count,Name,Edition,Card Number,Condition,Language,Foil,Signed,Artist Proof,Altered Art,Misprint,Promo,Textless,My Price

folder = "./collection/"

files = os.listdir(folder)

data_list = []

for f in files:
    data_list.append(pd.read_csv(folder + f))

collection_data = pd.concat(data_list)

collection_data["Foil"] = collection_data["Foil"].str.lower()

collection_data.rename(columns = {
        'Quantity': 'Count',
        '<Blank>':'Tradelist Count',
        'Collector\'s number': 'Card Number',
        '<Blank>.1':'Signed',
        '<Blank>.2':'Artist Proof',
        '<Blank>.3':'Altered Art',
        '<Blank>.4':'Misprint',
        '<Blank>.5':'Promo',
        '<Blank>.6':'Textless',
        '<Blank>.7':'My Price',
    }, inplace = True)

collection_data["Tradelist Count"] = collection_data["Count"]
collection_data["Collection"] = "Library"

collection_data.to_csv("collection.csv", sep=',', index=False, quoting=csv.QUOTE_ALL)