-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateJson.ts
299 lines (282 loc) · 7.83 KB
/
generateJson.ts
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import fs from 'fs';
import EbayService from "#services/EbayService";
import type {EbayItem, EbayItemDetailResponse, EbayLocalizedAspect} from "#types/ebay";
import type {Card} from "#types/payload";
type BaseInfo = {
keyword: string;
images: string[];
};
const baseInfos: BaseInfo[] = [
{
keyword: 'Flobio 36/106',
images: [
'IMG_3142.jpg',
'IMG_3143.jpg',
]
},
{
keyword: 'Chuchmur 82/101',
images: [
'IMG_3144.jpg',
'IMG_3145.jpg',
]
},
{
keyword: '74/101',
images: [
'IMG_3146.jpg',
'IMG_3147.jpg',
]
},
{
keyword: 'Meditikka 65/101',
images: [
'IMG_3148.jpg',
'IMG_3149.jpg',
]
},
{
keyword: 'Doduo 60/101',
images: [
'IMG_3150.jpg',
'IMG_3151.jpg',
]
},
{
keyword: 'Spinda 48/101',
images: [
'IMG_3152.jpg',
'IMG_3153.jpg',
]
},
{
keyword: 'Excavateur de fossiles 111/123',
images: [
'IMG_3154.jpg',
'IMG_3155.jpg',
]
},
{
keyword: 'Keunotor 73/123',
images: [
'IMG_3156.jpg',
'IMG_3157.jpg',
]
},
{
keyword: 'Ymphect 59/123',
images: [
'IMG_3158.jpg',
'IMG_3159.jpg',
]
},
{
keyword: 'Mustébouée 72/130',
images: [
'IMG_3160.jpg',
'IMG_3161.jpg',
]
},
{
keyword: 'Ceriflor 45/130',
images: [
'IMG_3162.jpg',
'IMG_3163.jpg',
]
},
{
keyword: 'Blindalys 44/130',
images: [
'IMG_3164.jpg',
'IMG_3165.jpg',
]
},
{
keyword: 'Chaglam 83/130',
images: [
'IMG_3166.jpg',
'IMG_3167.jpg',
]
},
{
keyword: 'Chenipotte 104/130',
images: [
'IMG_3168.jpg',
'IMG_3169.jpg',
]
},
{
keyword: 'Germignon 51/115',
images: [
'IMG_3170.jpg',
'IMG_3171.jpg',
]
},
{
keyword: 'Melofée 53/115',
images: [
'IMG_3172.jpg',
'IMG_3173.jpg',
]
},
{
keyword: 'Lainergie 56/115',
images: [
'IMG_3174.jpg',
'IMG_3175.jpg',
]
},
{
keyword: 'Axoloto 79/115',
images: [
'IMG_3176.jpg',
'IMG_3177.jpg',
]
},
{
keyword: 'Limagma 73/115',
images: [
'IMG_3178.jpg',
'IMG_3179.jpg',
]
},
{
keyword: 'Porygon 69/115',
images: [
'IMG_3180.jpg',
'IMG_3181.jpg',
]
},
{
keyword: 'Héricendre 45/101',
images: [
'IMG_3184.jpg',
'IMG_3185.jpg',
]
},
{
keyword: 'Abo 47/101',
images: [
'IMG_3186.jpg',
'IMG_3187.jpg',
]
},
{
keyword: 'Wattouat 54/101',
images: [
'IMG_3188.jpg',
'IMG_3189.jpg',
]
},
{
keyword: 'Méthode d\'entraînement du Prof. Orme 79/101',
images: [
'IMG_3192.jpg',
'IMG_3193.jpg',
]
},
{
keyword: 'Recherches du professeur Chen 149/165',
images: [
'IMG_3194.jpg',
'IMG_3195.jpg',
]
},
{
keyword: 'Piafabec 81/112',
images: [
'IMG_3196.jpg',
'IMG_3197.jpg',
]
},
{
keyword: 'Roucool 73/112',
images: [
'IMG_3198.jpg',
'IMG_3199.jpg',
]
},
{
keyword: 'Salamèche 58/112',
images: [
'IMG_3200.jpg',
'IMG_3201.jpg',
]
},
{
keyword: 'Herbe sauveuse 93/112',
images: [
'IMG_3202.jpg',
'IMG_3203.jpg',
]
},
{
keyword: 'Super Ball 92/112',
images: [
'IMG_3204.jpg',
'IMG_3205.jpg',
]
},
];
const ebayItems: Card[] = [];
for (const baseInfo of baseInfos) {
const items: EbayItem[] | undefined = await EbayService.findSimilarItems(baseInfo.keyword);
console.log("START SEARCHING FOR: " + baseInfo.keyword)
if (items) {
console.log(`Found ${items.length} items for keyword: ${baseInfo.keyword}`)
const ebayItem: Card = {
name: '',
number: '',
set: '',
language: '',
images: baseInfo.images,
isGraded: false,
startPrice: 1,
condition: 'Heavily Played (Poor)'
};
for (const item of items) {
const isLastItem: boolean = item === items[items.length - 1];
const itemId: string = item.itemId[0];
const details: EbayItemDetailResponse | undefined = await EbayService.findItemDetails(itemId);
console.log('LOCALIZED ASPECTS:', details?.localizedAspects);
// Extract number from title (e.g. 'Nirondelle 80/107' -> '80/107')
// Using a regular expression to find the first number in "xx/xx" format
const numberInTitle: string | null = item.title[0].match(/\b\d+\/\d+\b/)?.[0] || null;
if (details && details.localizedAspects) {
console.log(`Found details for item ID: ${itemId} successfully!`)
console.log(`Found ${details.localizedAspects.length} localized aspects for item ID: ${itemId} successfully!`)
// Assign values to ebayItem
if(!ebayItem.name) ebayItem.name = details.localizedAspects.find((aspect: EbayLocalizedAspect): boolean => aspect.name === 'Personnage')?.value || '';
if(!ebayItem.number) {
ebayItem.number = details.localizedAspects.find((aspect: EbayLocalizedAspect): boolean =>
(aspect.name === 'Numéro de carte') || (aspect.name === 'Numéro de pièce fabricant'))
?.value || numberInTitle || '';
}
if(!ebayItem.set) ebayItem.set = details.localizedAspects.find((aspect: EbayLocalizedAspect): boolean => aspect.name === 'Set')?.value || '';
if(!ebayItem.language) ebayItem.language = details.localizedAspects.find((aspect: EbayLocalizedAspect): boolean => aspect.name === 'Langue')?.value || '';
const missingFields: string[] = [];
if (!ebayItem.name) missingFields.push('name');
if (!ebayItem.number) missingFields.push('number');
if (!ebayItem.set) missingFields.push('set');
if (!ebayItem.language) missingFields.push('language');
console.log(`Missing fields: ${missingFields.join(', ')}`);
console.log('EBAY ITEM:', JSON.stringify(ebayItem, null, 4));
if(isLastItem && !ebayItem.name) {
ebayItem.name = baseInfo.keyword.split(' ')[0]
}
// Check if all necessary fields of ebayItem are filled
if (ebayItem.name && ebayItem.number && ebayItem.set && ebayItem.language) {
ebayItems.push(ebayItem);
console.log('RESULT EBAY ITEM:', JSON.stringify(ebayItem, null, 4));
break; // Stop the loop once a valid item is found
}
} else {
console.log(`No details found for item ID: ${itemId}`);
}
}
} else {
console.log(`No items found for keyword: ${baseInfo.keyword}`);
}
}
// Generate JSON file
fs.writeFileSync('items.json', JSON.stringify(ebayItems, null, 4));