elif data_type == 'sku': search_data = [row[0] for row in file_data[1:]] return search_data #determine SKU or node search data_type = search_type() search_level = 'cat.CATEGORY_ID' gws_df = pd.DataFrame() grainger_df = pd.DataFrame() if data_type == 'node': search_level = fd.blue_search_level() elif data_type == 'value' or data_type == 'name': while True: try: val_type = input('Search Type?:\n1. Exact value \n2. Value contained in field ') if val_type in ['1', 'EXACT', 'exact', 'Exact']: val_type = 'exact' break elif val_type in ['2', '%']: val_type = 'approx' break except ValueError: print('Invalid search type') search_data = data_in(data_type, settings.directory_name)
def generate_data(): gcom = GraingerQuery() #request the type of data to pull: blue or yellow, SKUs or node, single entry or read from file data_type = fd.search_type() search_level = 'cat.CATEGORY_ID' #if Blue is chosen, determine the level to pull L1 (segment), L2 (family), or L1 (category) if data_type == 'node': search_level = fd.blue_search_level() #ask user for node number/SKU or pull from file if desired search_data = fd.data_in(data_type, settings.directory_name) sku_status = skus_to_pull( ) #determine whether or not to include discontinued items in the data pull grainger_df = pd.DataFrame() if data_type == 'node': for k in search_data: if sku_status == 'filtered': temp_df = gcom.grainger_q(grainger_basic_query, search_level, k) temp_df = gcom.grainger_q(grainger_basic_query, search_level, k) elif sku_status == 'all': temp_df = gcom.grainger_q(grainger_discontinued_query, search_level, k) grainger_df = pd.concat([grainger_df, temp_df], axis=0) print(k) elif data_type == 'yellow': for k in search_data: if isinstance(k, int): #k.isdigit() == True: pass else: k = "'" + str(k) + "'" if sku_status == 'filtered': temp_df = gcom.grainger_q(grainger_basic_query, 'yellow.PROD_CLASS_ID', k) elif sku_status == 'all': temp_df = gcom.grainger_q(grainger_discontinued_query, 'yellow.PROD_CLASS_ID', k) grainger_df = pd.concat([grainger_df, temp_df], axis=0) print(k) elif data_type == 'sku': sku_str = ", ".join("'" + str(i) + "'" for i in search_data) if sku_status == 'filtered': grainger_df = gcom.grainger_q(grainger_basic_query, 'item.MATERIAL_NO', sku_str) elif sku_status == 'all': grainger_df = gcom.grainger_q(grainger_discontinued_query, 'item.MATERIAL_NO', sku_str) elif data_type == 'supplier': for k in search_data: if sku_status == 'filtered': temp_df = gcom.grainger_q(grainger_basic_query, 'supplier.SUPPLIER_NO', k) elif sku_status == 'all': temp_df = gcom.grainger_q(grainger_discontinued_query, 'supplier.SUPPLIER_NO', k) grainger_df = pd.concat([grainger_df, temp_df], axis=0) print(k) return [grainger_df, search_level]