Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from itertools import zip_longest
- def grouper(iterable, n, fillvalue=None):
- args = [iter(iterable)] * n
- return zip_longest(*args, fillvalue=fillvalue)
- with open("contentfile.txt", encoding="utf8") as file:
- paragraphs = file.read().split("\n\n")
- products = []
- for description_paragraph, tech_paragraph, spec_paragraph in grouper(paragraphs, 3):
- name, _, description = description_paragraph.partition("\n")
- description = description.split("\n")
- tech_bullet_points = tech_paragraph.split("\n")[1:]
- specs = {}
- for line in spec_paragraph.split("\n")[1:]:
- key, _, value = line.partition(": ")
- specs[key] = value
- product = {
- "name": name,
- "description": description,
- "features": tech_bullet_points,
- "specs": specs
- }
- products.append(product)
- print(products)
- with open("results.json", "w") as file:
- json.dump(products, file, indent=2)
- """
- result:
- [
- {
- "name": "Intimus pacmaster s",
- "description": [
- "The PacMaster S packaging material shredders allow businesses to recycle their cardboard packaging in a unique way.",
- "https://nonagon-paddlefish-5ywp.squarespace.com/s/IS_PacMasterS_VS_01-18_en.pdf"
- ],
- "features": [
- "Shreds old and obsolete cardboard to robust packaging material",
- "Well designed controls: lockable power switch is also an emergency stop switch",
- "Single pass operation",
- "Lockable master switch",
- "Size guide on the work surface to ensure accurate cutting of the cardboard to customise the stuffing mats to required format",
- "Extremely robust steel plate housing for heavy duty use at the packing station"
- ],
- "specs": {
- "Dimensions (H x W x D)": "37.4\" x 27.1\" x 18.5\" ",
- "Cutting Speed": "7.1 in/sec",
- "Supply Voltage": "400 V",
- "Noise level (dB(A))": "62-68.5",
- "Weight": "308.6 lbs"
- }
- },
- {
- "name": "",
- "description": [
- "HSM SHREDSTAR S10 ",
- "DOCUMENT SHREDDER",
- "Data protection for everyone. ",
- "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. ",
- "https://nonagon-paddlefish-5ywp.squarespace.com/s/HSM-shredstar-S10-1_4__1042123-1.pdf"
- ],
- "features": [
- "Automatic reverse eliminates paper jams. ",
- "Separate CD cutting unit with own waste container for sorted disposal.",
- "Quiet operation minimizes noise development in the workplace.",
- "LED indicator shows the device\u2019s operating status: Power, Overload, Overheat.",
- "Light barrier for automatic start/stop.",
- "Level indicator through inspection window in the waste container. ",
- "Effortless emptying of the waste container via the removable housing top."
- ],
- "specs": {
- "Dimensions (H x W x D)": "17.5\u201d x 13.6\u201d x 9.6\u201d",
- "Colour": "White ",
- "Motor": "125W",
- "Container/Collection Volume": "4.8 gal",
- "Intake width/ working width": "8.7 in",
- "Voltage/frequency": "115 V / 60 Hz ",
- "Cutting size": "1/4\"",
- "Cutting type": "strip",
- "Cutting capacity (in sheets)": "10",
- "Security level": "P-2/O-1/T-1/E-2",
- "Cutting Capabilities": "Paper, Staples & paperclips, Credit & customer cards, CDs & DVDs",
- "Weight (lbs)": "8.6"
- }
- },
- {
- "name": "HSM SHREDSTAR X5 ",
- "description": [
- "DOCUMENT SHREDDER",
- "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.",
- "https://nonagon-paddlefish-5ywp.squarespace.com/s/HSM-shredstar-X5-3_16_-x-1-1_8__1043123.pdf"
- ],
- "features": [
- "Automatic reverse eliminates paper jams. ",
- "Separate CD cutting unit with own waste container for sorted disposal.",
- "Quiet operation minimizes noise development in the workplace.",
- "LED indicator shows the device\u2019s operating status: Power, Overload, Overheat.",
- "Light barrier for automatic start/stop.",
- "Level indicator through inspection window in the waste container. ",
- "Effortless emptying of the waste container via the removable housing top."
- ],
- "specs": {
- "Dimensions (H x W x D)": "17.5\u201d x 13.6\u201d x 9.6\u201d",
- "Colour": "White ",
- "Motor": "125W",
- "Container/Collection Volume": "4.8 gal",
- "Intake width/ working width": "8.7 in",
- "Voltage/frequency": "115 V / 60 Hz ",
- "Cutting size": "3/16\u201d x 1 1/8\u201d",
- "Cutting type": "cross",
- "Cutting capacity (in sheets)": "5",
- "Security level": "P-4/O-1/T-1/E-2",
- "Cutting Capabilities": "Paper, Staples & paperclips, Credit & customer cards, CDs & DVDs",
- "Weight (lbs)": "9.3"
- }
- },
- {
- "name": "HSM SHREDSTAR X6pro ",
- "description": [
- "DOCUMENT SHREDDER",
- "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.",
- "https://nonagon-paddlefish-5ywp.squarespace.com/s/HSM-shredstar-X6pro-1_16_-x-5_8__1046113.pdf"
- ],
- "features": [
- "Automatic return eliminates paper jams. ",
- "Separate CD cutting unit with own waste container for sorted disposal.",
- "Quiet operation minimizes noise development in the workplace.",
- "LED indicator shows the operating state of the device",
- "Light barrier for automatic start/stop.",
- "Level indicator through inspection window in the waste container. ",
- "Effortless emptying of the waste container via the removable housing top."
- ],
- "specs": {
- "Dimensions (H x W x D)": "18.3\u201d x 13.6\u201d x 9.6\u201d",
- "Colour": "White ",
- "Motor": "160W",
- "Container/Collection Volume": "5.3 gal",
- "Intake width/ working width": "8.7 in",
- "Voltage/frequency": "115 V / 60 Hz ",
- "Cutting size": "1/16\u201d x 5/8\u201d",
- "Cutting type": "micro",
- "Cutting capacity (in sheets)": "6",
- "Security level": "P-5/O-1/T-1/E-2",
- "Cutting Capabilities": "Paper, Staples & paperclips, Credit & customer cards, CDs & DVDs",
- "Weight (lbs)": "13.9"
- }
- }
- ]
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement