Aug-09-2021, 09:14 AM
Hello,
I have created a code that update data into my DB according to my inputs
My question is that I want to make it "smarter" and be able to take data from Excel file.
So I can run it automatic for 150 IDs , but also to leave the option for manually update(if I will have 1 or 2, no need for excel file)
so I have this part:
the changes in the excel file are the same for all the ID (all ot them have the same old_com ,and will be change to the same new_com)
or it will be easy and better to create a new function ?
I have created a code that update data into my DB according to my inputs
def MainPage():
ID= input('What is the ID?\n\r')
OldCom = input('What is the old company ID?(1, 2, 3, 4\n\r')
NewCom = input('What is the new company ID?\n\r')
try:
ChangeCompany(ID, OldCom, NewCom)
except Exception as e:
print(e)this works with out any problems, when I enter the 3 values and it's update the DB successfully.My question is that I want to make it "smarter" and be able to take data from Excel file.
So I can run it automatic for 150 IDs , but also to leave the option for manually update(if I will have 1 or 2, no need for excel file)
so I have this part:
if __name__ == '__main__':
while True:
select = input('what to do? \n\r 1. Update ID\n\r 2. Update ID from Excel File \n\r 9. Exit \n\r')
if select == "1":
MainPage()
if select == "2":
wb_obj = openpyxl.load_workbook(xlsx_file)
sheet = wb_obj.active
print('you have ', str(sheet.max_row), ' lines of data')
for row in sheet.iter_rows(min_row=None):
ID = row[0].value # this is A1\A2\A3....... for the loop
if select == "9":
print('Goodbye!')
sys.exit()
if select not in ["1", "2", "9"]:
print('Wrong selection, try again!')can I use the same MainPage function ? like before ? the changes in the excel file are the same for all the ID (all ot them have the same old_com ,and will be change to the same new_com)
or it will be easy and better to create a new function ?
