#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import requests


from object.LanguageParser import LanguageParser

if __name__ == "__main__":

    parser = LanguageParser()
    enResult = parser.parser("./file/app_en_US.ts")
    cnResult = parser.parser("./file/app_zh_CN.ts")
    # print(cnResult)

    classKeys = enResult.keys()
    data = {}
    postData = {}
    url = 'http://192.168.136.35:8800/avss/add_single'
    for classKey in classKeys:
        classMap = {}
        data[classKey] = classMap
        classMap['name'] = classKey

        # 取出languages
        languageMap = {}
        languages = enResult[classKey]['languages']
        langKeys = languages.keys()
        for langKey in langKeys:
            language = languages[langKey]
            translation = []
            translation.append({'la_id': 20, 'val': language['translation']})
            translation.append({'la_id': 18, 'val': cnResult[classKey]['languages'][langKey]['translation']})

            language['translation'] = translation
            languageMap[langKey] = language

            postData['word_class'] = classKey
            postData['word_key'] = langKey
            postData['word_array'] = translation
            postData['location_array'] = language['locations']

            res = requests.post(url=url, data=json.dumps(postData))
            print(res)
        classMap['languages'] = languageMap
    print(data)



