<commit_before>import os
import requests
from lxml import etree
import sys
from django.conf import settings
from django.utils import translation
import language_map

settings.configure()

API_KEY = os.environ["CROWDIN_API_KEY"]
API_URL = "https://api.crowdin.com/api/project/cs-unplugged/{method}"

NS_DICT = {
    'ns': "urn:oasis:names:tc:xliff:document:1.2"
}

if len(sys.argv) != 2:
    raise Exception("Usage: python3 get_completed_translations.py <crowdin language code>")

SOURCE_LANGUAGE = "en"
TARGET_LANGUAGE = sys.argv[1]

def get_language_info(language):
    params = {
        "key" : API_KEY,
        "language": language
    }
    response = requests.get(
        API_URL.format(method="language-status"),
        params=params
    )
    info = etree.fromstring(response.text.encode())
    return info


def process_item(item, parent_path=None):
    if item.find("node_type").text == "file":
        filename = item.find("name").text
        if parent_path:
            path = os.path.join(parent_path, filename)
        else:
            path = filename

        # Skip full translated check for *.po - they can always be included
        if filename.endswith(".po"):
            return [path]

        if item.find("phrases").text == item.find("approved").text:
            return [path]
        else:
            return []

    else:
        inner_nodes = item.find("files")
        dirname = item.find("name").text
        if dirname == SOURCE_LANGUAGE:
            dirname = language_map.from_crowdin(TARGET_LANGUAGE)
        if parent_path:
            path = os.path.join(parent_path, dirname)
        else:
            path = dirname
        completed = []
        for inner_node in inner_nodes:
            completed += process_item(inner_node, parent_path=path)
        return completed


if __name__ == "__main__":
    lang_info = get_language_info(TARGET_LANGUAGE)
    files = lang_info.find("files")
    completed = []
    for item in files:
        completed += process_item(item)
    print('\n'.join(completed))
<commit_msg>Remove unnecessary imports from get_complete_translations.py<commit_after>import os
import requests
from lxml import etree
import sys
import language_map


API_KEY = os.environ["CROWDIN_API_KEY"]
API_URL = "https://api.crowdin.com/api/project/cs-unplugged/{method}"

NS_DICT = {
    'ns': "urn:oasis:names:tc:xliff:document:1.2"
}

if len(sys.argv) != 2:
    raise Exception("Usage: python3 get_completed_translations.py <crowdin language code>")

SOURCE_LANGUAGE = "en"
TARGET_LANGUAGE = sys.argv[1]

def get_language_info(language):
    params = {
        "key" : API_KEY,
        "language": language
    }
    response = requests.get(
        API_URL.format(method="language-status"),
        params=params
    )
    info = etree.fromstring(response.text.encode())
    return info


def process_item(item, parent_path=None):
    if item.find("node_type").text == "file":
        filename = item.find("name").text
        if parent_path:
            path = os.path.join(parent_path, filename)
        else:
            path = filename

        # Skip full translated check for *.po - they can always be included
        if filename.endswith(".po"):
            return [path]

        if item.find("phrases").text == item.find("approved").text:
            return [path]
        else:
            return []

    else:
        inner_nodes = item.find("files")
        dirname = item.find("name").text
        if dirname == SOURCE_LANGUAGE:
            dirname = language_map.from_crowdin(TARGET_LANGUAGE)
        if parent_path:
            path = os.path.join(parent_path, dirname)
        else:
            path = dirname
        completed = []
        for inner_node in inner_nodes:
            completed += process_item(inner_node, parent_path=path)
        return completed


if __name__ == "__main__":
    lang_info = get_language_info(TARGET_LANGUAGE)
    files = lang_info.find("files")
    completed = []
    for item in files:
        completed += process_item(item)
    print('\n'.join(completed))

{'fraction_non_alphanumeric': 0.1141732283464567, 'fraction_numerical': 0.0024606299212598425, 'mean_word_length': 2.6294642857142856, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5557801', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1237, 'n_words': 271}