Created
November 21, 2018 19:26
-
-
Save pengan1987/c2ae8caf53a9b06bf52197ec9d53ebb1 to your computer and use it in GitHub Desktop.
Translate item name to pinyin
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
| import json | |
| import pinyin | |
| with open('data.json', 'r') as f: | |
| loaded_data = json.load(f) | |
| newArr = [] | |
| for dataElem in loaded_data: | |
| pinName = pinyin.get(dataElem['name'], format="strip", delimiter="") | |
| pinName = pinName.replace(" - ","_") | |
| dataElem['id'] = pinName | |
| newArr.append(dataElem) | |
| print json.dumps(newArr, ensure_ascii=False).encode('utf8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment