Skip to content

Instantly share code, notes, and snippets.

@jc0b
Created April 21, 2023 11:34
Show Gist options
  • Select an option

  • Save jc0b/f1adfdfb63ae0862c8153be26e3e4d1f to your computer and use it in GitHub Desktop.

Select an option

Save jc0b/f1adfdfb63ae0862c8153be26e3e4d1f to your computer and use it in GitHub Desktop.
Gets the latest version of macOS from gdmf.apple.com/v2/pmv, and figures out when to enforce it.
import urllib.request
import json
import ssl
import datetime
# How many days after the release do you want to do this?
ENFORCEMENT_DATE_DELTA=14
# What time (UTC) do you want to have the deadline at?
UTC_UPDATE_TIME=14
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
def get_latest_release():
req = urllib.request.Request(url=f"https://gdmf.apple.com/v2/pmv", data=None, method="GET")
with urllib.request.urlopen(req, context=ctx) as response:
response_data = json.loads(response.read().decode('utf-8'))
latest_version = response_data['PublicAssetSets']['macOS'][-1]
print(f"The latest version of macOS is {latest_version['ProductVersion']}, posted on {latest_version['PostingDate']}")
publishing_date = datetime.datetime.strptime(latest_version['PostingDate'], '%Y-%m-%d')
enforcement_date = publishing_date + datetime.timedelta(days=ENFORCEMENT_DATE_DELTA, hours=UTC_UPDATE_TIME)
if enforcement_date.isoweekday() in set((6,7)): # if on a saturday or sunday
print("enforcement date on a weekend! moving to next weekday")
enforcement_date += datetime.timedelta(days=enforcement_date.isoweekday() % 5)
print(f"Enforcement date should be: {enforcement_date.strftime('%Y-%m-%dT%H:%M:%SZ')}")
if __name__ == '__main__':
get_latest_release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment