-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPLQ.py
57 lines (53 loc) · 2.28 KB
/
PLQ.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
from fuzzywuzzy import fuzz
import pandas as pd
from prettytable import PrettyTable
# Read in specific sheets of the Excel file
xl = pd.read_excel('pricelist_2023_03.xlsx', sheet_name=['Price List', 'MIST AI Access'])
while True:
# Get the name of the product to search for
product_name = input("Enter the name of the product: ")
x = PrettyTable()
x.field_names = ["Product Number", "Quantity", "Total Price","List Price","LOD","ADD","EOL Rep","Status"]
flag = 0
similar_list = []
for sheet_name, df in xl.items():
df["Product Number"] = df["Product Number"].str.lower()
match = df.loc[df['Product Number'] == product_name.lower()]
if not match.empty:
flag = 1
if pd.isna(match['Product List Price'].values[0]):
price = match['Service Price CAT 4'].values[0]
else:
price = match['Product List Price'].values[0]
while True:
try:
quantity = int(input("Enter the quantity of the product: "))
break
except ValueError:
print("Invalid input. Please enter a number.")
if not isinstance(price, str):
total_price = price * quantity
else:
total_price = "N/A"
description = match['Long Description'].values[0]
lod = str(match['LOD (Last Order Date)'].values[0])[0:10]
pbd = str(match['Price Book Date'].values[0])[0:10]
EOL_Replacement = match['EOL Replacement'].values[0]
material_status = match['Material Status'].values[0]
x.add_row([product_name.upper(),quantity, total_price,price,lod,pbd,EOL_Replacement,material_status])
print(x)
print(str(description))
print('\n')
break
else:
for product in df["Product Number"]:
ratio = fuzz.ratio(product_name.lower(), product.lower())
if ratio > 55:
similar_list.append(product)
if similar_list and flag == 0:
print("Did you mean:")
for item in similar_list:
print(f"{item.upper()}")
print("Please check again.")
if flag == 0:
print(f"{product_name} not found in any sheet.")