1 Star 0 Fork 0

passionboyxie/toutiao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
blurbs.py 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
passionboyxie 提交于 2020-10-26 18:15 . add some codes
import sys
import requests
#import langid
import numpy as np
import pandas as pd
#LANGUAGES = ['ar', 'de', 'en', 'es', 'fr', 'it', 'ja-JP', 'ko-KR', 'pt-BR', 'ru', 'th', 'tr-TR', 'zh-cn', 'zh-HK', 'zh-TW']
LANGUAGES = ['en', 'es', 'ru', 'zh-cn']
#ID = ['699126', '699124', '669751', '647306', '697256', '647306']
papa=pd.read_csv('/Users/anderson/work/blurbs.txt',sep='\t') #加载papa.txt,指定它的分隔符是 \t
ID = papa['ID']
url = "https://uat-ec-cn.eflabs.cn/services/school/query?q=blurb!{}&c=culturecode={}"
list_obj = []
class Translate():
def get_translated_string(self, blurb_id, language_code):
response = requests.post(url.format(blurb_id, language_code))
value = (response.json())[0]['translation'].strip()
print(blurb_id, value)
list_obj.append([blurb_id,value])
#return value
# def check_language(self, target, language):
# lineTuple = langid.classify(target) # 调用langid来对该行进行语言检测
# if "-" in language:
# language = language.split("-")[0]
# if lineTuple[0] != language:
# return False
# else:
# return True
def main():
translate = Translate()
for i in range(727699,727766):
translate.get_translated_string(i,'zh-cn')
result=pd.DataFrame(list_obj)
result.to_csv("blurbs2.csv")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/passionboyxie/toutiao.git
git@gitee.com:passionboyxie/toutiao.git
passionboyxie
toutiao
toutiao
master

搜索帮助