I am having quite the issue a program. I am working with the woocommere api to export daily orders from a website so I can automate the entry of them to our internal order system. The goal is to take csv that is produced from the api and format the columns in an easy way to grab with an rpg file that is already written. My issue is that in column R & S have nested dictionaries in them and I haven't been able to access those keys in the cell and then append them onto the csv. Hope this makes sense and someone can help. I can provide more clarification if necessary.
'''
import csv
#open a new input file
with open('buckorders.csv', 'r') as csv_file:
csv_reader = csv.DictReader(csv_file)
#open new output file
with open('buck_reformatted_orders.csv', 'w') as new_file:
#create column headers
fieldnames = ['id', 'status', 'date_created', 'total', 'line_items', 'billing', 'shipping', 'payment_method', 'payment_method_title']
csv_writer = csv.DictWriter(new_file, fieldnames=fieldnames)
#write out the fieldnames
csv_writer.writeheader()
for line in csv_reader:
billing_list = line['billing']
print(type(billing_list))
print(billing_list)
#delete all unneeded columns
del line['meta_data']
del line['refunds']
del line['shipping_tax']
del line['order_key']
del line['date_completed_gmt']
del line['discount_total']
del line['date_paid_gmt']
del line['prices_include_tax']
del line['tax_lines']
del line['parent_id']
del line['currency_symbol']
del line['created_via']
del line['_links']
del line['date_modified']
del line['discount_tax']
del line['total_tax']
del line['version']
del line['date_paid']
del line['customer_ip_address']
del line['cart_hash']
del line['customer_user_agent']
del line['transaction_id']
del line['date_completed']
del line['fee_lines']
del line['cart_tax']
del line['currency']
del line['customer_id']
del line['customer_note']
del line['shipping_total']
del line['date_modified_gmt']
del line['date_created_gmt']
del line['shipping_lines']
del line['coupon_lines']
del line['number']
csv_writer.writerow(line)
''' Link to google sheet for csv: buckorders.csv