Last active
July 29, 2020 18:17
-
-
Save flodolo/d6370aa26bf841c084be448ea8851682 to your computer and use it in GitHub Desktop.
Output CSV with selected products+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.request import urlopen | |
from urllib.parse import quote as urlquote | |
try: | |
query = ''' | |
{ | |
projects { | |
slug, | |
localizations { | |
locale | |
{ | |
code | |
} | |
} | |
} | |
} | |
''' | |
url = 'https://pontoon.mozilla.org/graphql?query={}'.format(urlquote(query)) | |
response = urlopen(url) | |
json_data = json.load(response) | |
# Leave empty to include all projects, except terminology | |
requested_products = [ | |
'android-l10n', 'firefox', 'firefox-for-ios', 'firefox-rocket' | |
] | |
coverage = {} | |
slugs = [] | |
for project in json_data['data']['projects']: | |
slug = project['slug'] | |
if slug == 'terminology': | |
continue | |
if requested_products and slug not in requested_products: | |
continue | |
if slug not in slugs: | |
slugs.append(slug) | |
for locale in project['localizations']: | |
loc = locale['locale']['code'] | |
if loc not in coverage: | |
coverage[loc] = [slug] | |
else: | |
if slug not in coverage[loc]: | |
coverage[loc].append(slug) | |
locales = list(coverage.keys()) | |
locales.sort() | |
slugs.sort() | |
output = [] | |
# Table Headers | |
output.append(','.join(['Locales'] + slugs)) | |
for locale in locales: | |
row = ['']*(len(slugs)+1) | |
row[0] = locale | |
for p in coverage[locale]: | |
row[slugs.index(p)+1] = 'x' | |
output.append(','.join(row)) | |
print('\n'.join(output)) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment