So I kinda know HTML but suck at python. As of now, I used Django(didn't understand) a web scraping module called beautiful soup(which didn't work). Basically what I am making is a billing software with item codes for items and a few varieties of quality and various costings per unit price.
I was able to figure out how to get the output part of the code working by using
txtfile.write(HTML)
.
I want my output as a table so I am specifically using pandas and also requesting for the answer output to have pandas.
NOTE: Can we do this without involving javascript at all? I don't want to use javascript because
- I didn't learn it
- I want to use only 1 programming language type thing
As of now, I have 3 problems:
- How to get input from HTML form and store it as a python variable
- How to format the output HTML part
- How to ensure that if I wanted to add more items, the python for loop will also be applicable to both the python calculation part and HTML part
I can work with either Tkinter or flask, flask is highly preferable.
This is the python code part
import pandas as p
from IPython.display import display
from tabulate import tabulate
import webbrowser
import os
import cgitb
cgitb.enable()
shop_bill = {'101A': ['Brown Rice', 50, 45.50, 41.25], '102B': ['Whole Wheat', 30, 27.45, 21.50],
'102C': ['Tomato Sauce', 25.50, 20.25, 18.70], '103D': ['Mustard', 40, 39.45, 37],
'104E': ['Barbeque Sauce',
45, 43, 41.50], '105F': ['Red Wine Vinegar', 4000, 3800, 3750], '106G': ['Salsa', 200, 180, 170],
'107H':
['Extra Virgin Olive Oil', 500, 478.50, 455.70], '108J': ['Canola Oil', 200, 180, 118],
'109J': ['Hot Pepper Sauce', 100, 98.50, 91.25],
'110K': ['Bananas', 60, 55, 50], '111L': ['Apples', 300, 250, 120], '112M': ['Oranges', 200, 140, 110],
'113M': ['Mangoes', 100, 80, 50], '114O': ['Strawberries', 100, 90, 80],
'115P': ['Blueberries', 95, 80, 75],
'116Q': ['Green Teas', 250, 225, 200], '117R': ['Sparkling Water', 20, 14.50, 11],
'118S': ['Dried Apricots',
270, 250, 230], '119T': ['Dried Figs', 100, 95, 90], '120U': ['Dried Prunes', 90, 85, 80],
'121V': ['Almonds',
900, 870, 850], '122W': ['Cashews', 1000, 950, 910], '123X': ['Walnuts', 800, 770, 720],
'124Y': ['Peanuts',
400, 380, 360], '125Z': ['Pecans', 350, 320, 300], '201A': ['Pistachios', 1200, 1180, 1160],
'202B': ['Sunflower Seeds',
150, 112.50, 103.45], '203C': ['Sesame Seeds', 120.50, 110.25, 101.40],
'204D': ['Whole Flaxseeds', 95.20, 90.45, 89.20]}
Registered_Cust = {'9500012345': ['Surian', 'AAA1001'], '9500023456': ['Nila', 'AAA1002'],
'9712300078': ['Arivazhagan', 'AAA1003'],
'9586233333': ['Nithin Kumar', 'AAA1004'], '6931245872': ['Aravind', 'AAA1005']}
ans = 'Y'
total_bill = 0
Cart = ''
Itemcodes = []
Items = []
Qualities = []
Quantities = []
Costings = []
while ans == 'Y':
Item_Code = input('Enter Item code for item: ').upper()
if Item_Code not in shop_bill:
print('Product unavailable/ Incorrect code. Try again')
continue
Itemcodes.append(Item_Code)
Items.append(shop_bill[Item_Code][0])
Qual = int(input('Enter quality you want to buy (1/2/3): '))
Qualities.append(Qual)
Quant = float(input('Enter quantity you want to buy (in kgs): '))
Quantities.append(Quant)
Price = (shop_bill[Item_Code][Qual]) * Quant
Costings.append(Price)
total_bill += Price
ans = input('Press Y to enter more items to cart: ').upper()
Phone = input('Enter mobile number: ')
if (len(Phone) != 10) or (Phone.isdecimal() == False):
print('Incorrect mobile number- try again')
Phone = input('Enter mobile number: ')
if Phone in Registered_Cust:
print('The customer is registered\n')
if total_bill > 5000:
total_bill -= total_bill * 0.02188
print('''Thankyou for being a loyal customer. You have earned cash rewards worth 1.2% of your total bill amount!
andd a discount of 1% \n''')
else:
print('customer not registered\n')
if total_bill > 10000:
total_bill -= total_bill * 0.01
print(' You gained an additional 1% discount on your purchase!')
bill_data = {'Item Code': Itemcodes, 'Item Name': Items, 'Quality': Qualities, 'Amount': Quantities,
'Item Cost': Costings}
bill_table = p.DataFrame(bill_data)
bill_table.style.set_table_styles([{'selector': '', 'props': [('border', '4px solid blue')]}])
print(tabulate(bill_table, headers='keys', tablefmt="pretty"))
html = bill_table.to_html()
txtfile = open('billing show.html', "w")
txtfile.write(html)
chillax=round(total_bill, 2)
chillbro=str(chillax)
txtfile.write("Your total bill is:"+chillbro)
txtfile.close()
print("Your total bill is:", round(total_bill, 2))
filename = 'file:///'+os.getcwd()+'/' + 'billing show.html'
webbrowser.open_new_tab(filename)
This is the html part
<h1 style="color:green;"
><em><b><marquee width="100%" direction="left" height="100px" scrollamount="25">ITEMS PRESENT IN VIT MART</marquee></b></em></h1>
</head><link rel="stylesheet" type="text/css" href="style%20(3).css">
<body style="background-image:url('/static/img/shop_logo.jpeg'); background-repeat: no-repeat; background-position:300px; background-color:#ff6500;">
<FORM method="get|POST" action="C:\Users\Altair\source\repos\PythonApplication4\templates\final_layout_2.html">
<br>
<br><b>Billing Counter:</b><br>
<TABLE border="1" style="background-color:blanchedalmond">
<TR>
<TD><label>Enter item code</label></TD>
<TD><input type="text" name="inputting_item_code" maxlength="7"></input></TD>
</TR>
<TR>
<TD><label>Enter item quality</label></TD>
<TD><input type="number" name="inputting_item_quality" =min="1" max="3"></input></TD>
</TR>
<TR>
<TD><label>Enter quantity</label></TD>
<TD><input name="inputting_item_quantity" type="number" ></input></TD>
</TR><TR>
<TR>
<TD><label>Would you like to add more items to the cart?(Y/N)</label></TD>
<TD><input type="text" name="inputting_more_item" maxlength="1" ></input></TD>
</TR>
</TABLE>
<p>Please enter your mobile number</p>
<P><INPUT TYPE="number" VALUE="mobile_number" NAME="customer_id_mobile" minlength="10" maxlength="10"></P>
<P><INPUT TYPE="SUBMIT" VALUE="Submit" NAME="B1"></P>
</FORM></body>
</html> ```