-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariants.py
63 lines (44 loc) · 1.74 KB
/
variants.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
import csv
import time
import shopify
import optparse
parser = optparse.OptionParser()
parser.add_option('--api_key', action="store" )
parser.add_option('--password', action="store" )
parser.add_option('--store_name', action="store" )
parser.add_option('--csv_file', action="store" )
parser.add_option('--variant_id', action="store" )
options, args = parser.parse_args()
if not options.api_key:
parser.error('--api-key not given not given')
if not options.password:
parser.error('--password not given not given')
if not options.store_name:
parser.error('--store_name not given not given')
if not options.csv_file:
parser.error('--csv_file not given not given')
shop_url = "https://%s:%s@%s/admin" % (options.api_key, options.password, options.store_name)
shopify.ShopifyResource.set_site(shop_url)
shop = shopify.Shop.current
with open(options.csv_file) as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
next(csvfile) # skip 2 lines
next(csvfile)
rowcount=0
bad_results = []
for row in readCSV:
variant_id = row[1]
if(options.variant_id and options.variant_id != variant_id):
continue
variant_price = row[3]
descr = "%s %s %s %s" % (row[6], row[7], row[8], row[9])
v=shopify.Variant.find(variant_id)
print(variant_id, variant_price, v.price)
if(float(v.price) != float(variant_price)):
my_err = "%s - %s - csv price: %s, shopify price: %s" % (variant_id, descr, float(variant_price), float(v.price))
bad_results.append(my_err)
if(rowcount % 2 == 0):
time.sleep(1)
rowcount += 1
print ("Error results\n")
print "\n".join(bad_results)