Last active
May 22, 2023 13:48
-
-
Save flodolo/75425dc1652ecaf8745fbfbc12f189ae to your computer and use it in GitHub Desktop.
Verify Windows Background Notifications experiment
This file contains 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 sys | |
from urllib.request import urlopen | |
# Get translations | |
translations_url = "https://raw.githubusercontent.com/mozilla-l10n/nimbus-l10n/main/.github/storage/windows_bg_notifications_2023.json" | |
try: | |
r = urlopen(translations_url) | |
translations = json.load(r)["translations"] | |
except Exception as e: | |
print(e) | |
# Verify translations | |
api_host = "https://experimenter.services.mozilla.com/api/v6/experiments" | |
mismatches = [] | |
for loc, loc_translations in translations.items(): | |
recipe_locale = "en" if loc == "en-US" else loc | |
experiment_id = f"backgroundtaskmessage-notification-release-4pct-{recipe_locale}" | |
try: | |
r = urlopen(f"{api_host}/{experiment_id}") | |
experiment_json = json.load(r) | |
for branch in experiment_json["branches"]: | |
if branch["slug"] == "control": | |
continue | |
content = branch["features"][0]["value"]["content"] | |
actions = content["actions"] | |
if branch["slug"] == "treatment-new": | |
mapping = { | |
"windows-bg-notifications-title-b": content["title"], | |
"windows-bg-notifications-title-c": content["body"], | |
"windows-bg-notifications-open-button-a": actions[0]["title"], | |
"windows-bg-notifications-remind-button-a": actions[1]["title"], | |
} | |
else: | |
mapping = { | |
"windows-bg-notifications-title-a": content["title"], | |
"windows-bg-notifications-body-a": content["body"], | |
"windows-bg-notifications-open-button-a": actions[0]["title"], | |
"windows-bg-notifications-remind-button-a": actions[1]["title"], | |
} | |
for k, v in mapping.items(): | |
#print(f"{loc}: {k} - {v}") | |
if loc_translations[k] != v: | |
mismatches.append( | |
f"Difference for: {loc}\n" | |
f"ID: {k}\n" | |
f"\nRecipe text:\n{v}\n" | |
f"\nRepository text:\n{loc_translations[k]}\n" | |
) | |
except Exception as e: | |
print(e) | |
if mismatches: | |
print("\n".join(mismatches)) | |
else: | |
print("No differences") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment