-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprice.py
148 lines (87 loc) · 3.16 KB
/
price.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
try:
import requests
import scrython
import imageio
import requests
import time
import config
import numpy as np
import os
import os.path
from fpdf import FPDF, HTMLMixin
import glob
from numpy.fft import fft2, ifft2, fftshift, ifftshift
from skimage.transform import resize
import pygame
import shutil
import subprocess
except ImportError:
print ("Trying to Install required module:")
os.system('pip3 install requests')
os.system('pip3 install scrython')
os.system('pip3 install imageio')
os.system('pip3 install time')
os.system('pip3 install numpy')
os.system('pip3 install pygame')
import shutil
import subprocess
import scrython
import imageio
import requests
import time
import config
import numpy as np
import os
import os.path
from fpdf import FPDF, HTMLMixin
import glob
from numpy.fft import fft2, ifft2, fftshift, ifftshift
from skimage.transform import resize
path2 = os.path.dirname(os.path.realpath(__file__))
print ("where is name txt for price's ?")
answer2=input("enter your_file.txt =>")
filePath2 = os.path.join(path2, answer2)
filePath3 = os.path.join(path2, "card.txt")
usd = "eur"
def nameBar(name, manaCost):
return "{} {}".format(name, manaCost)
def typeBar(typeLine, rarity):
return "{} | {}".format(typeLine, rarity[:1].upper())
def powerAndToughness(power, toughness):
return "{}/{}".format(power, toughness)
def process_card(cardname, expansion=None):
time.sleep(0.05)
# try/except in case the search doesn't return anything
try:
query = cardname
data = scrython.cards.Search(q=query)
for card in data.data():
text = str(query + "|" + card['set_name'])
eur = str(card["prices"]["eur"])
usd = str(card["prices"]["usd"])
print(card['name'] + "|", card['set_name'] + "|" + eur + "€"+ "|" + usd + "$")
text_file = open(path2+ "/"+"price.txt", "a")
text_file.write(text+ "|" + eur + "€" +"|"+ usd + "$"+ "\n" +"\n")
except scrython.foundation.ScryfallError:
print("Couldn't find card: " + cardname)
return
out=""
with open(filePath2) as f:
for ligne in f:
ligne=ligne.strip()
ligne=ligne.replace('Sideboard:', '').replace('Sauvegarder', '')
if ligne !='' and not ligne.startswith("//"):
n,mot=ligne.replace('SB:','').split(maxsplit=1)
out+=(mot+'\n')*int(n)
with open(filePath3,'w') as f:
f.write(out)
if __name__ == "__main__":
# Loop through each card in cards.txt and scan em all
with open(filePath3, 'r') as fp:
for cardname in fp:
cardname = cardname.rstrip()
try:
pipe_idx = cardname.index("|")
process_card(cardname[0:pipe_idx], cardname[pipe_idx+1:])
except ValueError:
process_card(cardname)