-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmtg_tcgp.py
executable file
·59 lines (45 loc) · 1.97 KB
/
mtg_tcgp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 08 12:33:44 2023
@author: Kannan Thambiah <[email protected]>
"""
import argparse
import numpy as np
import pandas as pd
def add_cards_to_db(db, count, booster, database_file):
for _, card in count.iterrows():
if card['Rarity'] == 'Token':
card['Set Code'] = f"T{card['Set Code']}"
index = db.index[(db['#'].astype(str) == str(card['Card Number'])) &
(db['Set'] == card['Set Code'])]
if len(index) > 0:
index = index[0]
stock = db.at[index, card['Printing']]
if np.isnan(stock):
db.at[index, card['Printing']] = int(card['Quantity'])
else:
db.at[index, card['Printing']] = int(stock + card['Quantity'])
if booster is not None:
boosters = db.at[index, 'Booster']
if pd.isnull(boosters):
db.at[index, 'Booster'] = booster
else:
db.at[index, 'Booster'] = \
f"{db.at[index, 'Booster']}, {booster}"
db.to_csv(index=False, path_or_buf=database_file)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-db', '--database', type=str, required=True,
help='Database file in CSV format')
parser.add_argument('-c', '--countfile', type=str, required=True,
help='File with count (in TCG-Player Format')
parser.add_argument('-b', '--booster', type=str, required=False,
help='Booster Number/Comment for field')
parsed_arguments = parser.parse_args()
database_file = parsed_arguments.database
count_file = parsed_arguments.countfile
booster = parsed_arguments.booster
database_csv = pd.read_csv(database_file, header=0)
count_csv = pd.read_csv(count_file, header=0)
add_cards_to_db(database_csv, count_csv, booster, database_file)