Advertisement
Guest User

Untitled

a guest
Oct 28th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. import json
  2. from itertools import zip_longest
  3. def grouper(iterable, n, fillvalue=None):
  4. args = [iter(iterable)] * n
  5. return zip_longest(*args, fillvalue=fillvalue)
  6.  
  7. with open("contentfile.txt", encoding="utf8") as file:
  8. paragraphs = file.read().split("\n\n")
  9.  
  10. products = []
  11. for description_paragraph, tech_paragraph, spec_paragraph in grouper(paragraphs, 3):
  12. name, _, description = description_paragraph.partition("\n")
  13. description = description.split("\n")
  14. tech_bullet_points = tech_paragraph.split("\n")[1:]
  15.  
  16. specs = {}
  17. for line in spec_paragraph.split("\n")[1:]:
  18. key, _, value = line.partition(": ")
  19. specs[key] = value
  20.  
  21. product = {
  22. "name": name,
  23. "description": description,
  24. "features": tech_bullet_points,
  25. "specs": specs
  26. }
  27. products.append(product)
  28.  
  29. print(products)
  30.  
  31. with open("results.json", "w") as file:
  32. json.dump(products, file, indent=2)
  33.  
  34.  
  35. """
  36. result:
  37.  
  38. [
  39. {
  40. "name": "Intimus pacmaster s",
  41. "description": [
  42. "The PacMaster S packaging material shredders allow businesses to recycle their cardboard packaging in a unique way.",
  43. "https://nonagon-paddlefish-5ywp.squarespace.com/s/IS_PacMasterS_VS_01-18_en.pdf"
  44. ],
  45. "features": [
  46. "Shreds old and obsolete cardboard to robust packaging material",
  47. "Well designed controls: lockable power switch is also an emergency stop switch",
  48. "Single pass operation",
  49. "Lockable master switch",
  50. "Size guide on the work surface to ensure accurate cutting of the cardboard to customise the stuffing mats to required format",
  51. "Extremely robust steel plate housing for heavy duty use at the packing station"
  52. ],
  53. "specs": {
  54. "Dimensions (H x W x D)": "37.4\" x 27.1\" x 18.5\" ",
  55. "Cutting Speed": "7.1 in/sec",
  56. "Supply Voltage": "400 V",
  57. "Noise level (dB(A))": "62-68.5",
  58. "Weight": "308.6 lbs"
  59. }
  60. },
  61. {
  62. "name": "",
  63. "description": [
  64. "HSM SHREDSTAR S10 ",
  65. "DOCUMENT SHREDDER",
  66. "Data protection for everyone. ",
  67. "This modern and compact strip cut document shredder with a separate CD cutting unit destroys your data reliably and quietly, both at home or in a small office. ",
  68. "https://nonagon-paddlefish-5ywp.squarespace.com/s/HSM-shredstar-S10-1_4__1042123-1.pdf"
  69. ],
  70. "features": [
  71. "Automatic reverse eliminates paper jams. ",
  72. "Separate CD cutting unit with own waste container for sorted disposal.",
  73. "Quiet operation minimizes noise development in the workplace.",
  74. "LED indicator shows the device\u2019s operating status: Power, Overload, Overheat.",
  75. "Light barrier for automatic start/stop.",
  76. "Level indicator through inspection window in the waste container. ",
  77. "Effortless emptying of the waste container via the removable housing top."
  78. ],
  79. "specs": {
  80. "Dimensions (H x W x D)": "17.5\u201d x 13.6\u201d x 9.6\u201d",
  81. "Colour": "White ",
  82. "Motor": "125W",
  83. "Container/Collection Volume": "4.8 gal",
  84. "Intake width/ working width": "8.7 in",
  85. "Voltage/frequency": "115 V / 60 Hz ",
  86. "Cutting size": "1/4\"",
  87. "Cutting type": "strip",
  88. "Cutting capacity (in sheets)": "10",
  89. "Security level": "P-2/O-1/T-1/E-2",
  90. "Cutting Capabilities": "Paper, Staples & paperclips, Credit & customer cards, CDs & DVDs",
  91. "Weight (lbs)": "8.6"
  92. }
  93. },
  94. {
  95. "name": "HSM SHREDSTAR X5 ",
  96. "description": [
  97. "DOCUMENT SHREDDER",
  98. "Data protection for the home or the small office. This modern and compact cross cut document shredder with a separate CD cutting unit shreds data in the workplace.",
  99. "https://nonagon-paddlefish-5ywp.squarespace.com/s/HSM-shredstar-X5-3_16_-x-1-1_8__1043123.pdf"
  100. ],
  101. "features": [
  102. "Automatic reverse eliminates paper jams. ",
  103. "Separate CD cutting unit with own waste container for sorted disposal.",
  104. "Quiet operation minimizes noise development in the workplace.",
  105. "LED indicator shows the device\u2019s operating status: Power, Overload, Overheat.",
  106. "Light barrier for automatic start/stop.",
  107. "Level indicator through inspection window in the waste container. ",
  108. "Effortless emptying of the waste container via the removable housing top."
  109. ],
  110. "specs": {
  111. "Dimensions (H x W x D)": "17.5\u201d x 13.6\u201d x 9.6\u201d",
  112. "Colour": "White ",
  113. "Motor": "125W",
  114. "Container/Collection Volume": "4.8 gal",
  115. "Intake width/ working width": "8.7 in",
  116. "Voltage/frequency": "115 V / 60 Hz ",
  117. "Cutting size": "3/16\u201d x 1 1/8\u201d",
  118. "Cutting type": "cross",
  119. "Cutting capacity (in sheets)": "5",
  120. "Security level": "P-4/O-1/T-1/E-2",
  121. "Cutting Capabilities": "Paper, Staples & paperclips, Credit & customer cards, CDs & DVDs",
  122. "Weight (lbs)": "9.3"
  123. }
  124. },
  125. {
  126. "name": "HSM SHREDSTAR X6pro ",
  127. "description": [
  128. "DOCUMENT SHREDDER",
  129. "Reliable and user-friendly micro cross cut document shredder with the highest security level in the shred star series. With a separate CD cutting unit for use in the workplace.",
  130. "https://nonagon-paddlefish-5ywp.squarespace.com/s/HSM-shredstar-X6pro-1_16_-x-5_8__1046113.pdf"
  131. ],
  132. "features": [
  133. "Automatic return eliminates paper jams. ",
  134. "Separate CD cutting unit with own waste container for sorted disposal.",
  135. "Quiet operation minimizes noise development in the workplace.",
  136. "LED indicator shows the operating state of the device",
  137. "Light barrier for automatic start/stop.",
  138. "Level indicator through inspection window in the waste container. ",
  139. "Effortless emptying of the waste container via the removable housing top."
  140. ],
  141. "specs": {
  142. "Dimensions (H x W x D)": "18.3\u201d x 13.6\u201d x 9.6\u201d",
  143. "Colour": "White ",
  144. "Motor": "160W",
  145. "Container/Collection Volume": "5.3 gal",
  146. "Intake width/ working width": "8.7 in",
  147. "Voltage/frequency": "115 V / 60 Hz ",
  148. "Cutting size": "1/16\u201d x 5/8\u201d",
  149. "Cutting type": "micro",
  150. "Cutting capacity (in sheets)": "6",
  151. "Security level": "P-5/O-1/T-1/E-2",
  152. "Cutting Capabilities": "Paper, Staples & paperclips, Credit & customer cards, CDs & DVDs",
  153. "Weight (lbs)": "13.9"
  154. }
  155. }
  156. ]
  157. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement