In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how Python uses Youdao Translation to develop API". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how Python uses Youdao Translation to develop API".
Python source code is about Python using Youdao Translation to develop API application example. This is a very interesting and simple API application exercise, the method uses the youdao dictionary open API application, the synthesis is similar to the command line dictionary application Python Mini Program. The function is simple, but the effect is very good.
It should be noted here that the frequency limit of youdao API is 1000 requests per hour. If the limit is exceeded, it will be blocked.
Tip: if you want to use this all the time, you can apply for a KEY yourself, the application process is very simple, just replace the original KEY_FROM and KEY.
Python uses Youdao Translation to develop API application examples. The source codes are as follows:
#! / usr/bin/env python#-*-coding: utf-8-*-# www.iplaypy.com import urllib2import urllibimport simplejson as jsonimport sys class YoudaoDic (): "" youdao dictionary API "" VERSION = 1.1URL = 'http://fanyi.youdao.com/openapi.do' KEY_FROM =' Dic-EVE' KEY = '975360059' TYPE =' data' # optional value xml Json DOC_TYPE = 'json' def translate (self, text): translation method Pass in the text to be translated Return the result dictionary "" # Parameter params = {'keyfrom': self.KEY_FROM,' key': self.KEY, 'type': self.TYPE,' doctype': self.DOC_TYPE, 'version': self.VERSION,' Qothers: text} request = urllib2.urlopen (self.URL) Urllib.urlencode (params)) data = request.read () return json.loads (data) def format_for_command (self, text): "" format the translation result for the command line "" data = main (text) # TODO: format string if data: print 'Youdao Translation:' print'\ t original text:' Data.get ('query', text) translation = data.get (' translation', None) if translation: for t in translation: print'\ t translation:' T else: 'cannot find the word' def main (text): if text and text.strip ()! =': return YoudaoDic (). Translate (text) if _ name__ = ='_ main__': if sys.argv and len (sys.argv) > = 2: l = sys.argv [1:] YoudaoDic (). Format_for_command (''. Join (l)) else: print 'Youdao Translation:\ n\ t Tip: please enter the words or sentences you want to translate' Thank you for your reading The above is the content of "how Python uses Youdao Translation to develop API". After the study of this article, I believe you have a deeper understanding of how Python uses Youdao Translation to develop API, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.