Last active
January 12, 2021 16:49
-
-
Save flodolo/34751c070fdc9078094dee0037376e89 to your computer and use it in GitHub Desktop.
Check monitor locales
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
#!/usr/bin/env python3 | |
import json | |
from urllib.parse import quote as urlquote | |
from urllib.request import urlopen | |
def main(): | |
# Get completion stats for locales from Pontoon | |
query = """ | |
{ | |
firefox: project(slug: "firefox-monitor-website") { | |
localizations { | |
locale { | |
code | |
}, | |
missingStrings, | |
totalStrings | |
} | |
} | |
} | |
""" | |
pontoon_stats = {} | |
try: | |
print("Reading Pontoon stats...") | |
url = "https://pontoon.mozilla.org/graphql?query={}".format(urlquote(query)) | |
response = urlopen(url) | |
json_data = json.load(response) | |
for project, project_data in json_data["data"].items(): | |
for element in project_data["localizations"]: | |
locale = element["locale"]["code"] | |
pontoon_stats[locale] = round( | |
(float(element["totalStrings"] - element["missingStrings"])) | |
/ element["totalStrings"] | |
* 100, | |
2, | |
) | |
except Exception as e: | |
print(e) | |
try: | |
print("Reading production locales from packages.json") | |
prod_config = "https://raw.githubusercontent.com/mozilla/blurts-server/main/package.json" | |
response = urlopen(prod_config) | |
json_data = json.load(response) | |
monitor_locales = json_data["supportedLocales"] | |
except Exception as e: | |
print(e) | |
threshold = 70 | |
below_threshold = [] | |
missing = [] | |
for locale, completion in pontoon_stats.items(): | |
if locale not in monitor_locales: | |
if completion > threshold: | |
missing.append(locale) | |
else: | |
if completion < threshold: | |
below_threshold.append(locale) | |
missing.sort() | |
below_threshold.sort() | |
if below_threshold: | |
print( | |
"\nLocales below {}% threshold ({}):".format( | |
threshold, len(below_threshold) | |
) | |
) | |
for locale in below_threshold: | |
print("{} ({}%)".format(locale, pontoon_stats[locale])) | |
else: | |
print( | |
"\nNo locales below {}% threshold ({}).".format( | |
threshold, len(below_threshold) | |
) | |
) | |
if missing: | |
print("\nLocales missing from production ({}):".format(len(missing))) | |
for locale in missing: | |
print("{} ({}%)".format(locale, pontoon_stats[locale])) | |
else: | |
print("\nNo locales missing from production.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment