Last active
March 21, 2025 16:20
-
-
Save linusg/f998d24564bfd5583006cdd5efbe8fc8 to your computer and use it in GitHub Desktop.
Generate macOS model identifier / device name mapping from Apple support pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import re | |
import requests | |
DEVICE_NAME_MODEL_IDENTIFIER_REGEX = r"<strong>(.*)\s*(?:<br>\s*</strong>|</strong>\s*<br>)\s*.*\s*Model (?:Label|Identifier):\s*(.*)\s*<br>" | |
SUPPORT_URLS = [ | |
# iMac | |
"https://support.apple.com/en-gb/HT201634", | |
# MacBook Air | |
"https://support.apple.com/en-gb/HT201862", | |
# MacBook Pro | |
"https://support.apple.com/en-gb/HT201300", | |
# Mac mini | |
"https://support.apple.com/en-gb/HT201894", | |
# Mac Pro | |
"https://support.apple.com/en-gb/HT202888", | |
] | |
identifiers = {} | |
for url in SUPPORT_URLS: | |
html = requests.get(url).text.replace(" ", " ") | |
for device_name, model_identifiers in reversed( | |
re.findall( | |
DEVICE_NAME_MODEL_IDENTIFIER_REGEX, html, re.IGNORECASE | re.MULTILINE | |
) | |
): | |
for model_identifier in model_identifiers.split(";"): | |
identifiers[model_identifier.strip()] = device_name.strip() | |
print(json.dumps(identifiers, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment