Join Momo, the High Priestess of Koho, in 'Momodora: Moonlit Farewell'! This latest installment in the Momodora series invites you to embark on a divine mission to save your village from demon hordes summoned by a malevolent bellringer. Experience stunning pixel art, action-packed gameplay, and deep exploration in a lore-rich world. Customize your play style with the innovative 'Sigil' system and prepare for intense boss battles. With adjustable difficulty levels, you can relax and explore or take on mighty foes for a real challenge. Get your EU PS5 CD Key today!
To solve this problem, we need to reformat a given input in JSON format into a structured HTML output. The input may contain system requirements for different operating systems (OS), each specified with various hardware and software requirements. The goal is to convert this input into a user-friendly HTML format that clearly presents the system requirements for each OS.
### Approach
1. **Input Analysis**: The input is an array of objects where each object contains system requirements. Each requirement can be either a direct key-value pair (e.g., OS, Processor) or a pre-formatted HTML string under a "requirement" key.
2. **HTML Structure**: For each system (e.g., Windows, Mac, Linux), we need to create a `
` with a class "prod-spec". This div will contain an `
` heading indicating the system, a paragraph stating "MINIMUM SPECS", and an unordered list of requirements.
3. **Mapping Keys to Labels**: Certain keys like "OS" need to be converted into more readable labels. For example, "OS" becomes "Operating System".
4. **Parsing HTML Requirements**: If the requirements are provided as a pre-formatted HTML string, we need to parse this string to extract individual list items and reformat them within our structure.
5. **Output Formatting**: Ensure the final HTML is correctly formatted with proper indentation and spacing, including line breaks (`
`) where necessary.
### Solution Code
Here is the step-by-step solution to reformat the given JSON input into the desired HTML structure:
```python
import json
from bs4 import BeautifulSoup
import re
def reformat_html(json_input):
data = json.loads(json_input)
html_output = []
for item in data:
if 'system' in item and 'requirement' in item:
system = item['system']
requirement_html = item['requirement']
# Parse the HTML to extract list items
soup = BeautifulSoup(requirement_html, 'html.parser')
ul = soup.find('ul')
lis = ul.find_all('li')
# Create the HTML structure for this system
system_html = f'''
{system} System Requirements
MINIMUM SPECS
'''
for li in lis:
# Convert strong tags to span with appropriate label
spans = li.find_all('span')
if spans:
for span in spans:
label = span.text.strip()
# Handle special case for "OS:" which might be from the HTML
if label == 'OS:':
label = 'Operating System:'
value = span.next_sibling.strip()
system_html += f'- {label} {value}
'
else:
# Handle case where the HTML does not have spans
parts = li.text.strip().split(':', 1)
if len(parts) > 1:
label, value = parts
system_html += f'- {label}: {value}
'
else:
system_html += f'- {li.text.strip()}
'
system_html += '
'
html_output.append(system_html)
else:
# Handle case where each item is a key-value pair
system_type = 'PC' # Default if not specified
if 'OS' in item:
system_type = ' '.join(item['OS'].split()[:1])
# Start building the HTML for this system
system_html = f'''
{system_type} System Requirements
MINIMUM SPECS
'''
for key, value in item.items():
if key == 'OS':
label = 'Operating System:'
else:
label = re.sub(r'(?{label} {value}'
system_html += '
'
html_output.append(system_html)
# Join all system requirement divs with two line breaks between them
full_html = '\n
\n
\n'.join(html_output)
return full_html
# Example usage:
json_input = '[{"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(json_input))
```
### Explanation
1. **Parsing JSON Input**: The input JSON is parsed to extract each system's requirements.
2. **Handling Different Requirements Formats**: The code checks if each item contains a "system" and "requirement" key. If so, it parses the HTML string to extract each requirement. Otherwise, it directly uses the key-value pairs.
3. **Mapping Keys to Labels**: Special keys like "OS" are converted to more readable labels (e.g., "Operating System").
4. **Building HTML Structure**: Each system's requirements are formatted into `
` elements with appropriate headings and lists.
5. **Concatenating Output**: The HTML parts for each system are joined with line breaks to ensure proper spacing.
This approach ensures that the system requirements are presented in a clear and structured manner, enhancing readability and user experience.
-
Go to http://www.SonyEntertainmentNetwork.com.
-
Click "Manage Account" and sign in with your Sign-In ID(E-mail Address) and Password.
-
Click on "Redeem Prepaid Card".
-
Enter the code printed on the voucher or PlayStation Network Card and click "Continue".
-
If the code is valid, you will be presented with a description of what the code will deliver to your account.
-
Press "Redeem..." button to add the item or funds to your account.
分享