Skip to content

Commit 0a27dee

Browse files
committed
Improve the saved file
1 parent 040ed2e commit 0a27dee

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

stripe_python/util.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,30 @@ def get_products( stripeApiKEY, outputFile='products.json'):
1414
productdict = []
1515
for product in products:
1616
dict= {}
17-
dict['id' ] = product['id']
18-
dict['Name' ] = product['name']
19-
dict['Description' ] = product['description']
20-
dict['Images' ] = product['images']
21-
dict['Price_Default' ] = { product["default_price"]["id"]: product["default_price"]["unit_amount"]/100}
17+
dict['id' ] = product['id']
18+
dict['name' ] = product['name']
19+
dict['description' ] = product['description']
20+
dict['images' ] = product['images']
21+
22+
# Get default price
23+
dict['price_default' ] = { product["default_price"]["id"]: product["default_price"]["unit_amount"]/100}
24+
25+
# Pull all prices
2226
all_prices = stripe.Price.list(product=product["id"]).data
2327
pricedict = {}
2428

29+
# Save all prices
2530
for price in all_prices:
2631
pricedict[price["id"]] = price["unit_amount"] / 100
2732

28-
dict['Prices'] = pricedict
33+
dict['prices'] = pricedict
2934
productdict.append(dict)
3035

3136
with open(outputFile, "w") as outfile:
32-
json.dump({"data": productdict}, outfile)
3337

38+
# json.dump({"data": productdict}, outfile)
39+
40+
products = json.dumps( {"data": productdict}, indent=4, separators=(',', ': ') )
41+
42+
outfile.write( products )
43+
outfile.close()

0 commit comments

Comments
 (0)