Guillaume
11/08/2022, 1:51 PMGavin
11/08/2022, 2:58 PMimport requests
import urllib3
import tzlocal
import json
import datetime
#
# Read the file nudge.json and return the JSON object
#---
def read_json_file(file_name):
with open(file_name) as json_file:
return json.load(json_file)
#
# Get latest macOS version from <https://gdmf.apple.com/v2/pmv>
#---
def get_latest_macos_version():
url = "<https://gdmf.apple.com/v2/pmv>"
# disable the
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
response = requests.get(url, verify=False)
products = response.json()["PublicAssetSets"]["macOS"]
lastest_version = 0
# if the version is two dots long make it three by adding a zero to the end
# version is a string in the key ProductVersion which needs converting to a float
for product in products:
version = product["ProductVersion"]
if len(version.split(".")) == 2:
version = version + ".0"
version = int(version.replace(".", ""))
if version > lastest_version:
lastest_version = version
return lastest_version
#
# Convert to macOS version string and let's hope there is not a 12.10.0
#---
def convert_int_to_version_string(version):
version = str(version)
version = version[0:2] + "." + version[2:3] + "." + version[3:4]
return version
def main():
# This should ideally be a command line argument for a file name.
nudge_data = read_json_file("nudge.json")
nudge_current_version = nudge_data["osVersionRequirements"][0][
"requiredMinimumOSVersion"]
latestMacOSUpdate = get_latest_macos_version()
# if the nudge_current_version is less than the latestMacOSUpdate then update the nudge.json file and make the nudge_instalL_date 30 days from now the date format is ISO-8601
if int(nudge_current_version.replace(".", "")) < latestMacOSUpdate:
nudge_data["osVersionRequirements"][0][
"requiredMinimumOSVersion"] = convert_int_to_version_string(
latestMacOSUpdate)
# make the required installation date 30 days from time now
nudge_data["osVersionRequirements"][0][
"requiredInstallationDate"] = str(
tzlocal.get_localzone().localize(datetime.datetime.now() +
datetime.timedelta(
days=30)).isoformat())
with open("nudge.json", "w") as json_file:
json.dump(nudge_data, json_file, indent=4)
if __name__ == "__main__":
main()
allister
11/14/2022, 3:32 AMlet's hope there is not a 12.10.0
lol