代码拉取完成,页面将自动刷新
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")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。