-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatePrices.py
54 lines (51 loc) · 1.53 KB
/
updatePrices.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
import csv
import os
from pymilvus import (
connections,
utility,
FieldSchema,
CollectionSchema,
DataType,
Collection,
)
connections.connect("default", host="localhost", port="19530")
collection = Collection('mtgCards')
onedrive = os.environ["OneDrive"]
# the directory to write cards to.
mtgDocDir = os.path.join(onedrive, "Documents\\Real World\\Collections\\mtg")
for folder,_,fnames in os.walk(mtgDocDir):
for fname in fnames:
if not fname.endswith('.csv'):
continue
oldTotal = 0
newTotal = 0
name = os.path.join(folder,fname)
reader = csv.reader(open(name,newline=''))
rows = []
for row in reader:
foil = row[3].lower()=='true'
s,_,cnum = row[0].partition('-')
res = collection.query(
expr=f"set == '{s}' and collector_number == '{cnum}'",
output_fields=["prices"],
)
prices = res[0]['prices']
price = 0
if foil:
price = prices['usd_foil']
else:
price = prices['usd']
try:
oldTotal += int(100*float(row[2]))
except:
pass
try:
newTotal += int(100*float(price))
except:
pass
row[2]=price
rows.append(row)
writer = csv.writer(open(name,'w',newline=''))
for row in rows:
writer.writerow(row)
print(fname,oldTotal/100,newTotal/100)