Discover the world with an Airbnb $75 Gift Card! This gift card allows you to find vacation rentals, cabins, beach houses, and unique homes across the globe. Whether you're planning a weekend getaway or a long vacation, this card is perfect for anyone looking to create unforgettable experiences. Gift it to friends or family and let them choose their next adventure!
To solve this problem, we need to create an intelligent HTML reformatting agent that can transform a given JSON input into a structured HTML format. The output HTML should follow specific guidelines, including the use of classes, headers, and lists for system requirements.
### Approach
1. **Parse the Input JSON**: The input can be in two forms:
- Single system requirements with multiple key-value pairs.
- Multiple systems, each with their own set of requirements.
2. **Generate HTML Structure**:
- For each system, create a `
` with the class "prod-spec".
- Include a `
` heading with the system name.
- Add a `
` tag with the text "MINIMUM SPECS".
- Create a `
` to list each requirement, where each requirement is a `- ` containing a `` for the key and the value.
3. **Handle Requirements**:
- If the input is a single system, directly map each key-value pair to a list item.
- If the input contains multiple systems, iterate through each system and generate the corresponding HTML.
4. **Special Handling for Requirement Strings**:
- Some requirement strings might already contain HTML elements. These need to be parsed to extract individual requirements and convert them into the required format.
5. **Ensure HTML Validity**: Make sure all tags are correctly closed and that the structure adheres to the examples provided.
### Solution Code
```python
import json
def reformat_html(input_json):
# Parse the input JSON
data = json.loads(input_json)
html_output = []
# Check if the data contains multiple systems
if isinstance(data[0], dict) and "system" in data[0]:
for system_data in data:
system_name = system_data["system"]
requirements = system_data["requirement"]
# Remove any existing
tags from requirements
requirements = requirements.replace('', '')
# Split into individual list items
li_items = [item.strip() for item in requirements.split('- ') if item.strip() != '']
# Process each li item to extract key and value
processed_items = []
for item in li_items:
if '' in item:
key = item.split('')[1].split('')[0].strip()
value = item.split('')[1].strip()
processed_items.append({"key": key, "value": value})
# Construct the HTML for this system
html = f'
{system_name} System Requirements
MINIMUM SPECS
'
for item in processed_items:
html += f'- {item["key"]}: {item["value"]}
'
html += '
'
html_output.append(html)
else:
# Single system data
html = 'System Requirements
MINIMUM SPECS
'
for requirement in data:
key = next(iter(requirement.keys()))
value = requirement[key]
html += f'- {key}: {value}
'
html += '
'
html_output.append(html)
# Join all parts and return
return ''.join(html_output).replace('\n', '')
```
### Explanation
The provided solution works by first parsing the input JSON to determine whether it contains single or multiple system requirements. For each system, it constructs an HTML `` with appropriate headers, paragraphs, and lists. The requirements are processed to extract keys and values, which are then formatted into list items. The solution handles both plain text and pre-formatted HTML strings, ensuring that the output adheres to the specified structure. This approach ensures that the resulting HTML is clean, well-formatted, and meets the user's guidelines.
-
To redeem the card go to https://www.airbnb.pt/gift and log into your account.
-
Gift cards can be used for any stay, Experience or Online Experience on Airbnb.
-
Once you redeem your card and add the funds from the card to your account, you can go to Payment methods in your Account and check your balance.
-
Once a gift card has been added to your Airbnb account, the funds won’t expire.
Be the first to review this product!
Share