Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- logging.debug("option 1 selected")
- #check if file exists
- exists = os.path.isfile('stores.dat')
- if exists:
- print('creating phone book')
- with open('stores.dat', 'r') as input_file:
- #open stores.dat
- lines = input_file.readlines()
- newLines = [] # new line array
- for line in lines:
- registers2 = 21 #for the while loop
- while registers2 <= 30: #while loop for selection 1, suppposed to print 6 registers for each store
- if registers2 < 27:
- stores = line[:4] #truncates the stores.dat after 4 chars
- if (int(stores) >= 4 and int(stores) != 172) and int(stores) <= 173:
- IP = ('999.24.' + str(stores.strip('0')) + '.1' + str(registers2))
- elif int(stores) == 172 or int(stores) >= 174:
- if int(stores) < 200:
- IP = ('20.6.' + str(abs(int(stores)) % 100) + '.3' + str(abs(int(registers2)) % 10))
- if int(stores) > 200:
- IP = ('20.6.' + str(abs(int(stores)) % 100) + '.3' + str(abs(int(registers2)) % 10))
- registers = stores + "Registers" , 'Register ' + str(registers2),IP,'Store ' + stores.strip('0') + '' + ' - Register ' + str(registers2), '', "LAN (TCP)", '', '', '', '','','', '', '', '0x1'
- newLines.append(registers)
- elif registers2 == 28:
- if int(stores.strip('0'))< 174:
- IPcc = '555.70.' + stores.strip('0') + '.5'
- IPdd = '555.70.' + stores.strip('0') + '.7'
- CCcontroller = stores + "Controllers", 'CC Controller', IPcc, 'Store ' + stores.strip('0') + ' - CC Controller', '', "LAN (TCP)", '', '', '','','', '', '', '', '0x1'
- DDcontroller = stores + "Controllers", 'DD Controller', IPdd,'Store ' + stores.strip('0') + ' - DD Controller', '', "LAN (TCP)", '', '', '','','', '', '', '', '0x1'
- newLines.append(CCcontroller)
- newLines.append(DDcontroller)
- if int(stores.strip('0')) >= 174:
- if int(stores.strip('0')) < 200:
- IPcc = '11.1.' + str(abs(int(stores.strip('0'))) % 100) + '.99'
- IPdd = '11.1.' + str(abs(int(stores.strip('0'))) % 100) + '.88'
- if int(stores.strip('0')) > 200:
- IPcc = '11.2.' + str(abs(int(stores.strip('0'))) % 100) + '.99'
- IPdd = '12.2.' + str(abs(int(stores.strip('0'))) % 100) + '.88'
- CCcontroller = stores + "Controllers", 'CC Controller', IPcc, 'Store ' + stores.strip('0') + ' - CC Controller ', '', "LAN (TCP)", '', '', '', '', '', '', '', '', '0x1'
- DDcontroller = stores + "Controllers", 'DD Controller', IPdd, 'Store ' + stores.strip('0') + ' - DD Controller ', '', "LAN (TCP)", '', '', '', '', '', '', '', '', '0x1'
- newLines.append(CCcontroller)
- newLines.append(DDcontroller)
- registers2 = registers2 + 1
- with open('file.csv', 'w',newline='') as output_file:
- file_writer = csv.writer(output_file)
- file_writer.writerows(newLines)
- print('phonebook saved as file.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement