Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. logging.debug("option 1 selected")
  2. #check if file exists
  3. exists = os.path.isfile('stores.dat')
  4.  
  5. if exists:
  6. print('creating phone book')
  7. with open('stores.dat', 'r') as input_file:
  8. #open stores.dat
  9. lines = input_file.readlines()
  10. newLines = [] # new line array
  11. for line in lines:
  12.  
  13. registers2 = 21 #for the while loop
  14.  
  15.  
  16. while registers2 <= 30: #while loop for selection 1, suppposed to print 6 registers for each store
  17.  
  18. if registers2 < 27:
  19.  
  20. stores = line[:4] #truncates the stores.dat after 4 chars
  21.  
  22. if (int(stores) >= 4 and int(stores) != 172) and int(stores) <= 173:
  23. IP = ('999.24.' + str(stores.strip('0')) + '.1' + str(registers2))
  24.  
  25.  
  26. elif int(stores) == 172 or int(stores) >= 174:
  27. if int(stores) < 200:
  28. IP = ('20.6.' + str(abs(int(stores)) % 100) + '.3' + str(abs(int(registers2)) % 10))
  29.  
  30. if int(stores) > 200:
  31. IP = ('20.6.' + str(abs(int(stores)) % 100) + '.3' + str(abs(int(registers2)) % 10))
  32.  
  33. registers = stores + "Registers" , 'Register ' + str(registers2),IP,'Store ' + stores.strip('0') + '' + ' - Register ' + str(registers2), '', "LAN (TCP)", '', '', '', '','','', '', '', '0x1'
  34.  
  35. newLines.append(registers)
  36.  
  37. elif registers2 == 28:
  38. if int(stores.strip('0'))< 174:
  39.  
  40. IPcc = '555.70.' + stores.strip('0') + '.5'
  41. IPdd = '555.70.' + stores.strip('0') + '.7'
  42.  
  43. CCcontroller = stores + "Controllers", 'CC Controller', IPcc, 'Store ' + stores.strip('0') + ' - CC Controller', '', "LAN (TCP)", '', '', '','','', '', '', '', '0x1'
  44.  
  45. DDcontroller = stores + "Controllers", 'DD Controller', IPdd,'Store ' + stores.strip('0') + ' - DD Controller', '', "LAN (TCP)", '', '', '','','', '', '', '', '0x1'
  46.  
  47. newLines.append(CCcontroller)
  48. newLines.append(DDcontroller)
  49.  
  50. if int(stores.strip('0')) >= 174:
  51.  
  52. if int(stores.strip('0')) < 200:
  53. IPcc = '11.1.' + str(abs(int(stores.strip('0'))) % 100) + '.99'
  54. IPdd = '11.1.' + str(abs(int(stores.strip('0'))) % 100) + '.88'
  55.  
  56. if int(stores.strip('0')) > 200:
  57. IPcc = '11.2.' + str(abs(int(stores.strip('0'))) % 100) + '.99'
  58. IPdd = '12.2.' + str(abs(int(stores.strip('0'))) % 100) + '.88'
  59.  
  60. CCcontroller = stores + "Controllers", 'CC Controller', IPcc, 'Store ' + stores.strip('0') + ' - CC Controller ', '', "LAN (TCP)", '', '', '', '', '', '', '', '', '0x1'
  61.  
  62. DDcontroller = stores + "Controllers", 'DD Controller', IPdd, 'Store ' + stores.strip('0') + ' - DD Controller ', '', "LAN (TCP)", '', '', '', '', '', '', '', '', '0x1'
  63.  
  64. newLines.append(CCcontroller)
  65. newLines.append(DDcontroller)
  66.  
  67.  
  68. registers2 = registers2 + 1
  69.  
  70. with open('file.csv', 'w',newline='') as output_file:
  71. file_writer = csv.writer(output_file)
  72. file_writer.writerows(newLines)
  73. print('phonebook saved as file.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement