-
Notifications
You must be signed in to change notification settings - Fork 3
/
to_excel.py
46 lines (37 loc) · 1007 Bytes
/
to_excel.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
import sys, pyperclip
from aliexpress_importer import *
print('=' * 60)
print('DOUBLE CHECK PRODUCT PRICES!!! THEY MAY BE WRONG!!!')
print('=' * 60)
if len(sys.argv) != 2:
print(f'Usage: py {sys.argv[0]} <urls.txt>')
quit(1)
with open(sys.argv[1], 'r') as f:
urls = [url for url in f.read().splitlines() if url.strip()[0] != '#']
IMPORTER = Importer()
lines = []
with open('backup_clipboard.txt', 'w+', encoding='utf-8') as f:
for url in urls:
p: Product = None
for tries in range(10):
try:
p = IMPORTER.import_product(url)
except Exception as e:
print(type(e).__name__, e)
print('Retrying...' if tries < 9 else 'Proceeding...')
else:
break
if p:
line = [
p.name,
f'=HYPERLINK("{url}","X")',
p.skus[1].full_price,
p.shipping_fee,
1,
(p.shipping_fee + p.skus[1].full_price) * 1.5 + .13 * 9.99,
.13
]
lines.append('\t'.join([str(v) for v in line]))
final_text = '\n'.join(lines)
f.write(final_text)
pyperclip.copy(final_text)