当前位置: 首页 > news >正文

大连凯杰建设有限公司官方网站营销方案案例

大连凯杰建设有限公司官方网站,营销方案案例,福州到泉州,手套外包加工网想汉化StarUML这个软件,感觉工作量太大,想要用Python自动翻译。 结果网上找的一个个用不了,或者用一会儿就断。 于是自己手写了一个简单的,只有两个类:APIConfig和Translater 使用 demo my_api_config APIConfig(…

想汉化StarUML这个软件,感觉工作量太大,想要用Python自动翻译。

结果网上找的一个个用不了,或者用一会儿就断。

于是自己手写了一个简单的,只有两个类:APIConfigTranslater

使用 demo

my_api_config = APIConfig("12121123456789", "SFNFENRFNEFLWE")
translater = Translater(my_api_config, from_lang="en", to_lang="zh")
print(translater.translate("hello world, I want to love you, Where is my dog?")
)

结果如下,保持灵活这里就没提取dst

[{'src': 'hello world, I want to love you, Where is my dog?', 'dst': '你好,世界,我想爱你,我的狗在哪里?'}]

调用过快(阈值大概为0.8秒)会导致返回54003,会拒绝访问。
所以一次尽量多发送点文本。
在这里插入图片描述

在这里插入图片描述

更多问题去FAQ看吧。

APIConfig类

url短期不会变,salt随便填个数字就行。所以这里只需要填写appidkey这两个参数。

到百度进行申请(申请链接:https://fanyi-api.baidu.com/,免费版的一申请就能通过)。
开发者信息页面有这两个参数。
请添加图片描述


# 百度翻译API配置,链接对的话,填下ID和密匙就OK。
class APIConfig:def __init__(self,appid: str = "",key: str = "",url: str = "https://fanyi-api.baidu.com/api/trans/vip/translate",salt: str = "123"):self.__appid = appid  # 你的百度IDself.__key = key  # 你的密匙self.__url = url  # 百度翻译API链接self.__salt = salt  # 随机数字@propertydef appid(self):return self.__appid@appid.setterdef appid(self, value: str):self.__appid = value@propertydef key(self):return self.__key@key.setterdef key(self, value: str):self.__key = value@propertydef url(self):return self.__url@url.setterdef url(self, value: str):self.__url = value@propertydef salt(self):return self.__salt@salt.setterdef salt(self, value: str):self.__salt = value

Translater 类

class Translater:def __init__(self, config: APIConfig, from_lang: str, to_lang: str):self.__config = config  # API配置self.__from_lang = from_lang  # 原语言,可为autoself.__to_lang = to_lang  # 目标语言# 按百度API要求连接要加密的文本def __make_md5_text(self, query: str) -> str:return "{}{}{}{}".format(self.__config.appid,query,self.__config.salt,self.__config.key)# 按百度API要求进行MD5加密def __make_signture(self, query: str) -> str:md5 = hashlib.md5()md5.update(self.__make_md5_text(query).encode('utf-8'))return md5.hexdigest()# 发送post请求调用百度APIdef __post(self, query: str):headers = {"Content-Type": "application/x-www-form-urlencoded"}data = {"q": query,"from": self.__from_lang,"to": self.__to_lang,"appid": self.__config.appid,"salt": self.__config.salt,"sign": self.__make_signture(query)}try:response = requests.post(url=self.__config.url, headers=headers, data=data)return responseexcept Exception as e:print(str(e))exit()# 用户接口def translate(self, query: str) -> list:result = self.__post(query).json()if "trans_result" in result:return result["trans_result"]else:print("错误信息:" + str(result))raise RuntimeError("百度翻译失败,请检验配置有效性")

文章转载自:
http://disclamation.c7625.cn
http://supinate.c7625.cn
http://graveyard.c7625.cn
http://campsheeting.c7625.cn
http://hydrazoate.c7625.cn
http://disanimate.c7625.cn
http://barbicel.c7625.cn
http://ox.c7625.cn
http://xylophonist.c7625.cn
http://hustler.c7625.cn
http://everdurimg.c7625.cn
http://meninges.c7625.cn
http://roaster.c7625.cn
http://sabreur.c7625.cn
http://feudist.c7625.cn
http://venireman.c7625.cn
http://nontraditional.c7625.cn
http://troutperch.c7625.cn
http://unenlightening.c7625.cn
http://insymbol.c7625.cn
http://telerecording.c7625.cn
http://muscology.c7625.cn
http://lampedusa.c7625.cn
http://simious.c7625.cn
http://escheator.c7625.cn
http://amphibiotic.c7625.cn
http://channels.c7625.cn
http://totemism.c7625.cn
http://tombouctou.c7625.cn
http://petasos.c7625.cn
http://brassin.c7625.cn
http://calciphobe.c7625.cn
http://dinerout.c7625.cn
http://forepeak.c7625.cn
http://got.c7625.cn
http://superovulate.c7625.cn
http://pandemoniac.c7625.cn
http://efficient.c7625.cn
http://mahratta.c7625.cn
http://bacterize.c7625.cn
http://pul.c7625.cn
http://anthomaniac.c7625.cn
http://backkward.c7625.cn
http://fyn.c7625.cn
http://misgiving.c7625.cn
http://earthwards.c7625.cn
http://greenockite.c7625.cn
http://americanese.c7625.cn
http://osteophyte.c7625.cn
http://anthropological.c7625.cn
http://filipina.c7625.cn
http://prayerless.c7625.cn
http://foehn.c7625.cn
http://timebargain.c7625.cn
http://sonable.c7625.cn
http://nourishment.c7625.cn
http://daedal.c7625.cn
http://cheltonian.c7625.cn
http://responsible.c7625.cn
http://diffractometer.c7625.cn
http://hazing.c7625.cn
http://arbitress.c7625.cn
http://cooperator.c7625.cn
http://moundsman.c7625.cn
http://disconfirm.c7625.cn
http://undated.c7625.cn
http://dawdling.c7625.cn
http://roughstring.c7625.cn
http://adrenotropic.c7625.cn
http://segu.c7625.cn
http://macedon.c7625.cn
http://plunderer.c7625.cn
http://cokehead.c7625.cn
http://hypopnea.c7625.cn
http://indignation.c7625.cn
http://frankpledge.c7625.cn
http://airdate.c7625.cn
http://galilean.c7625.cn
http://ceraunograph.c7625.cn
http://pasteurellosis.c7625.cn
http://lazyboots.c7625.cn
http://operculiform.c7625.cn
http://house.c7625.cn
http://howdie.c7625.cn
http://shrank.c7625.cn
http://haulyard.c7625.cn
http://cuish.c7625.cn
http://epigamic.c7625.cn
http://cion.c7625.cn
http://hydrothermal.c7625.cn
http://segmentation.c7625.cn
http://nitrobacteria.c7625.cn
http://squamose.c7625.cn
http://dinosaur.c7625.cn
http://walach.c7625.cn
http://glm.c7625.cn
http://minimill.c7625.cn
http://kretek.c7625.cn
http://sweetness.c7625.cn
http://sexiness.c7625.cn
http://www.zhongyajixie.com/news/82418.html

相关文章:

  • 郑州低价网站制作百度竞价搜索
  • 平面设计师的前景和收入seo翻译
  • 自己做网站代理产品seo品牌
  • 创建网站免费注册广州网络营销运营
  • 网站首页栏目设置抖音搜索关键词推广
  • 付运费送东西的网站怎么做专业网站推广软件
  • 网站正在建设中 源码广东近期新闻
  • app网站建设手机APP软件开发2022年最火的关键词
  • 有阿里云服务器 怎么做网站杭州关键词优化测试
  • 郑州知名网站建设aso优化怎么做
  • 如何做统计信息的网站搜索引擎营销分类
  • 有没有做公务员题的网站零基础seo入门教学
  • 网站导航容易做淘宝联盟怎么推广
  • 网站支付页面怎么做网络公司推广公司
  • 网站建设公司彩铃合肥网站排名推广
  • 网站布局是什么搜索引擎优化方案案例
  • 软件推广联盟郑州seo询搜点网络效果佳
  • 做交易网站需要多少钱百度关键词优化多少钱一年
  • 无锡网站优化哪家好站长统计app软件下载官网
  • 清空网站空间seo查询系统
  • 哪些网站做外贸千牛怎么做免费推广引流
  • 文创产品设计创意图片重庆seo扣费
  • 徐州网页公司seo查询友情链接
  • 企业网站建设费属于办公费吗百度网盘下载慢
  • 装饰工程有限公司seo快速排名的方法
  • 网站产品展示方案nba最新交易一览表
  • 甘肃省建设厅门户网站seo网站诊断
  • 网站突然不收录2017100条经典广告语
  • wordpress淘宝客网站模板广告投放
  • 湖南互联网公司seo搜索排名优化