I have a script that imports a list from another file. The list contains an almost-dictionary, so I ran a loop through it to turn it into a dictionary, but I'm getting the following error:
Redefinition of unused productOrdersListPulled
What am I doing wrong?
My code is:
import ast
import re
from api import productOrdersListPulled
# This script removes some characters from the messy dictionaries,
# Afterwards, they are a dictionary, recognizable by python
# regex to find unneeded data in the file
order_item = re.compile("<OrderProducts at 0x[\da-f]+, ({.*?})>", re.I)
def transformInDictionary(productOrdersListPulled):
# opens up the file with the unstructured data, and use it as a iterator
for line in productOrdersListPulled:
productOrdersListWithLine = [ast.literal_eval(op) for op in re.findall(order_item, line)]
return productOrdersListWithLine
transformInDictionary()
And the other file is:
import bigcommerce
# Script used to pull OrderProducts data from the Big Commerce API.
# login to bigcommerce api
api = bigcommerce.api.BigcommerceApi(host='*******.mybigcommerce.com', basic_auth=('**********', '*************'))
# create lists
def createLists():
productOrdersList = list()
ordersList = list()
productsList = list()
return productOrdersList, ordersList, productsList
# update range if orders ids goes higher than this
# try,except, pass added so the for loop keeps looping even if IDs are not found
# remember to update range (higest so far: 615982)
def pullOrdersProductsData(productOrdersList):
for x in range(614530, 614535):
try:
productOrdersList.append(api.Orders.get(id="{}".format(x)).products())
except:
pass
return productOrdersList
# loop over the list and get the orders with the IDs
def pullOrders(ordersList):
# remember to update range (higest so far: 615982)
for x in range(614534, 614535):
try:
ordersList.append(api.Orders.get(id="{}".format(x)))
except:
pass
return ordersList
def pullProductsData(productsList):
# loop over the list and get the products with the Ids
# dont forget to update range (highest so far 2000)
for x in range(0, 5):
try:
productsList.append(api.Products.get(id="{}".format(x)))
except:
pass
return productsList
productOrdersListPulled, ordersListPulled, productsListPulled = createLists()
pullOrdersProductsData(productOrdersListPulled)
pullOrders(ordersListPulled)
pullProductsData(productsListPulled)