Advertisement
eric11144

sheet_load

Jun 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. @classmethod
  2. def load(cls, sheet):
  3. '''Return configuration in dict-list like:'''
  4. config_list = []
  5. for row in range(3, sheet.max_row+1):
  6. row_str = str(row)
  7. for col in range(ord('A'), ord('I')):
  8. col_str = chr(col)
  9. if(sheet[col_str + row_str].value):
  10. # if (sheet['A'+row_str].value and
  11. # sheet['B'+row_str].value and
  12. # sheet['C'+row_str].value and
  13. # sheet['D'+row_str].value and
  14. # sheet['E'+row_str].value and
  15. # sheet['F'+row_str].value and
  16. # sheet['G'+row_str].value):
  17. polling_config = {
  18. 'endPoint': {
  19. 'host': sheet["A"+row_str].value,
  20. 'port': sheet["B"+row_str].value
  21. },
  22. 'pollingPeriodMS': sheet["C"+row_str].value,
  23. 'requestTimeoutMS':sheet["D"+row_str].value,
  24. 'equipments': [{
  25. 'id': sheet["E"+row_str].value,
  26. 'templateId': sheet["F"+row_str].value,
  27. 'equipmentId': sheet["G"+row_str].value,
  28. 'equipmentName':sheet["H"+row_str].value
  29. }]
  30. }
  31.  
  32. row += 1
  33.  
  34. for equ_row in range(row, sheet.max_row+1):
  35. equ_row_str = str(equ_row)
  36. if (sheet['A'+equ_row_str].value or
  37. sheet['B'+equ_row_str].value or
  38. sheet['C'+equ_row_str].value or
  39. sheet['D'+equ_row_str].value):
  40. break
  41.  
  42. equipment = {
  43. 'id': sheet["E"+equ_row_str].value,
  44. 'templateId':sheet["F"+equ_row_str].value,
  45. 'equipmentId':sheet["G"+equ_row_str].value,
  46. 'equipmentName':sheet["H"+equ_row_str].value
  47. }
  48. polling_config["equipments"].append(equipment)
  49. row += 1
  50. config_list.append(polling_config)
  51. else:
  52. # TODO log warning here
  53. continue
  54. return config_list
  55.  
  56. ```
  57. like
  58.  
  59. polling_config = {
  60. 'endPoint': {
  61. 'host': sheet["A"+row_str].value,
  62. 'port': sheet["B"+row_str].value
  63. },
  64. 'pollingPeriodMS': sheet["C"+row_str].value,
  65. 'requestTimeoutMS': sheet["D"+row_str].value,
  66. 'equipments': [{
  67. 'id': sheet["E"+row_str].value,
  68. 'templateId': sheet["F"+row_str].value,
  69. 'equipmentId': sheet["G"+row_str].value,
  70. 'equipmentName': sheet["H"+row_str].value
  71. },
  72. {
  73. 'id': sheet["E"+row_str].value,
  74. 'templateId': sheet["F"+row_str].value,
  75. 'equipmentId': sheet["G"+row_str].value,
  76. 'equipmentName': sheet["H"+row_str].value
  77. },
  78. {
  79. 'id': sheet["E"+row_str].value,
  80. 'templateId': sheet["F"+row_str].value,
  81. 'equipmentId': sheet["G"+row_str].value,
  82. 'equipmentName': sheet["H"+row_str].value
  83. }]
  84. }
  85.  
  86. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement