Step into the world of feudal Japan with Assassin’s Creed Shadows! Play as Naoe, a stealthy shinobi Assassin, and Yasuke, a legendary samurai, navigating a beautifully crafted open world filled with chaos and adventure. Master unique playstyles, build your shinobi league, and customize your hideout while uncovering their intertwined destinies. Experience dynamic weather, recruit allies, and unlock new skills to dominate your enemies. Perfect for fans of action-adventure games!
To solve this problem, we need to reformat a given list of system requirements into a structured HTML format. The goal is to ensure that the output is clean, well-formatted, and adheres to the specified structure. The system requirements can either be for a single system or multiple systems, each with their own set of requirements.
### Approach
1. **Identify the Structure**: Determine if the input consists of a single system or multiple systems based on the presence of a "system" key in the input objects.
2. **Extract Requirements**: For each system, extract the relevant requirements. If the requirement is provided as an HTML snippet, parse it to extract key-value pairs.
3. **Reformat Requirements**: Convert each key-value pair into the specified HTML structure. Each requirement should be listed with the key in a span followed by the value.
4. **Construct HTML**: Wrap each system's requirements in a div with the appropriate class. Include the system name, a heading, and a minimum specs line. Separate multiple systems with line breaks.
### Solution Code
```python
import json
def reformat_html(input_json):
data = json.loads(input_json)
html_parts = []
# Determine if the input contains multiple systems
has_system_key = any('system' in item for item in data)
for item in data:
if has_system_key:
system_name = item['system']
requirement = item['requirement']
else:
system_name = "PC"
requirement = item
# Extract key-value pairs
items = []
if has_system_key:
from bs4 import BeautifulSoup
soup = BeautifulSoup(requirement, 'html.parser')
list_items = soup.find('ul').find_all('li')
for li in list_items:
strong = li.find('strong')
if strong:
key = strong.get_text().strip().rstrip(':')
value = li.get_text().split(':', 1)[1].strip()
items.append((key, value))
else:
for key, value in requirement.items():
items.append((key, value))
# Construct the HTML for this system
system_html = f'''
{system_name} System Requirements
MINIMUM SPECS
'''
for key, value in items:
system_html += f'''-
{key}: {value}
'''
system_html += '
'
html_parts.append(system_html)
# Combine all parts with appropriate separators
full_html = '
'.join(html_parts)
return full_html
# Example usage:
input_json = '''[{"OS":"Windows XP or Windows Vista"},{"Processor":"1.8 GHz"},{"Memory":"512MB RAM (1 GB recommended)"},{"Graphics":"3D graphics card compatible with DirectX 8 (compatible with DirectX 9 recommended)"},{"Hard Drive":"2GB"},{"Additional":"Mouse, Keyboard"}]'''
print(reformat_html(input_json))
```
### Explanation
1. **Extract and Parse**: The code first parses the input JSON to determine whether it contains multiple systems or a single system. If it contains multiple systems, it extracts the system name and requirement HTML for each.
2. **BeautifulSoup Parsing**: For each system with requirement HTML, it uses BeautifulSoup to parse the HTML and extract key-value pairs. These pairs are then structured into the required format.
3. **Construct HTML**: Each system's requirements are wrapped in a div with appropriate classes and headings. The key-value pairs are formatted into ordered list items with spans for the keys.
4. **Combine Systems**: Multiple systems are combined with separating line breaks to ensure proper formatting.
This approach ensures that the system requirements are presented in a clean, readable, and well-structured HTML format.
-
Press the Xbox button to open the guide, and then select Store.
-
Press the View button to open the side menu, and then select Redeem.
-
Enter the 25-character code, select Next, and then follow the prompts.
-
Press the Guide button on your controller.
-
Select Games & Apps, and then select Redeem Code.
-
Enter the 25-character code, and then follow the prompts to complete your redemption.
分享