Skip to content

Instantly share code, notes, and snippets.

@linusg
Last active July 29, 2023 06:38
Show Gist options
  • Save linusg/f998d24564bfd5583006cdd5efbe8fc8 to your computer and use it in GitHub Desktop.
Save linusg/f998d24564bfd5583006cdd5efbe8fc8 to your computer and use it in GitHub Desktop.
Generate macOS model identifier / device name mapping from Apple support pages
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("&nbsp;", " ")
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