Use an Apple gift card to purchase iPhones, iPods, MacBooks, and other Apple products from any Apple store. Apple Cards can only be used to purchase Apple hardware! This is NOT an iTunes gift card!
To solve this problem, we need to reformat system requirements data into an HTML structure following specific guidelines. The goal is to transform input data into a structured HTML format that is easy to read and display on a web page.
### Approach
1. **Understand the Input Structure**: The input can be an array of objects where each object contains system components and their respective requirements. These objects can either represent different systems (e.g., Windows, Mac, Linux) with nested requirements or individual components under a single system (e.g., PC).
2. **Parse Requirements**: If the requirements are provided as HTML strings, we need to parse these strings to extract relevant components and their details. This involves converting each list item within the HTML into appropriate HTML elements.
3. **Construct the HTML Output**: For each system, create a `
` with a heading indicating the system type. Inside this div, include a bold text for "MINIMUM SPECS" and a list where each item consists of a component name and its requirement.
4. **Handle Multiple Systems**: If the input contains multiple systems, each system's requirements should be contained within its own div. Separate these divs with `
` tags to ensure proper formatting.
5. **Formatting and Validation**: Ensure that the HTML output is properly formatted and free of markup errors. Validate the output against given examples to confirm it meets the specified structure.
### Solution Code
```python
import json
from bs4 import BeautifulSoup
import re
def reformat_html(input_str):
data = json.loads(input_str)
html_output = []
for item in data:
if 'system' in item:
system = item['system']
requirements = item['requirement']
if requirements.startswith('
'):
soup = BeautifulSoup(requirements, 'html.parser')
requirements_list = []
for li in soup.find_all('li'):
strong_tag = li.find('strong')
if strong_tag:
key = strong_tag.text.strip()
value = li.text[len(key)+1:].strip()
requirements_list.append({key: value})
else:
requirements_list = [item]
html = f''
html += f'
{system} System Requirements
'
html += '
'
html += '
MINIMUM SPECS
'
html += '
'
for req in requirements_list:
for key, value in req.items():
formatted_key = re.sub(r':$', '', key).strip()
formatted_key = formatted_key.replace('_', ' ').capitalize()
html += f'- {formatted_key}: {value}
'
html += '
'
html_output.append(html)
else:
html = 'PC System Requirements
'
html += '
MINIMUM SPECS
'
for req in data:
key = list(req.keys())[0]
value = req[key]
formatted_key = key.replace('_', ' ').capitalize()
html += f'- {formatted_key}: {value}
'
html += '
'
html_output.append(html)
html_output = '
'.join(html_output)
return html_output
```
### Explanation
The provided solution is a Python function that takes a JSON string as input and returns the reformatted HTML. Here's a breakdown of how it works:
1. **Input Parsing**: The input string is parsed into a JSON object to extract system requirements data.
2. **System Identification**: Each item is checked to determine if it represents a specific system (e.g., Windows, Mac) or a general PC system.
3. **HTML Parsing**: If the system's requirements are provided as an HTML string, the function uses BeautifulSoup to parse and extract the relevant components.
4. **HTML Construction**: For each system, an HTML div is constructed with appropriate headings and list items. Each component and its requirement are formatted into list items within an unordered list.
5. **Output Formatting**: Multiple systems are separated by `
` tags to ensure the output is neatly formatted.
This approach ensures that the system requirements are presented in a structured and readable manner, adhering to the specified guidelines.
-
Open the App Store on your device.
-
Sign-in to your account.
-
Choose the Redeem Gift Card or Code option.
-
Enter the purchased Apple gift card code.
-
Finish the process by pressing Redeem.
Seien Sie der Erste, der dieses Produkt bewertet!
Teilen