Last active
June 10, 2016 10:53
-
-
Save samundra/d07bd2e312f7c3d0b65de4b68c91b22d to your computer and use it in GitHub Desktop.
Mutate_google_translate.py
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
| #!/usr/bin/python2 | |
| #!encoding = utf-8 | |
| # filename: ~/.config/Mutate/scripts | |
| import re | |
| import urllib | |
| import urllib2 | |
| import json | |
| import sys | |
| reload(sys) | |
| sys.setdefaultencoding('utf-8') | |
| #text command icon subtext | |
| def has_chinese_charactar(content): | |
| try: | |
| iconvcontent = unicode(content) | |
| zhPattern = re.compile(u'[\u4e00-\u9fa5]+') | |
| match = zhPattern.search(iconvcontent) | |
| res = False | |
| if match: | |
| res = True | |
| return res | |
| except: | |
| return True | |
| for i in range(1, len(sys.argv)): | |
| if has_chinese_charactar(sys.argv[i]): | |
| source_languege = "zh-CN" | |
| target_languege = "en" | |
| else: | |
| source_languege = "en" | |
| target_languege = "th" #change final translation language here | |
| url = 'http://translate.google.cn/translate_a/t' | |
| payload = { | |
| 'client': 'p', | |
| 'text' : sys.argv[i], | |
| 'hl' : 'en-EN', | |
| 'sl' : source_languege, | |
| 'tl' : target_languege, | |
| 'multires': '1', | |
| 'ssel' : '0', | |
| 'tsel' : '0', | |
| 'sc' : '1', | |
| 'ie' : 'UTF-8', | |
| 'oe' : 'UTF-8' | |
| } | |
| response = urllib2.Request(url,urllib.urlencode(payload)) | |
| browser = "Mozilla/5.0 (Windows NT 6.1; WOW64)" | |
| response.add_header('User-Agent', browser) | |
| response = urllib2.urlopen(response) | |
| get_page = response.read() | |
| print '[' + get_page + ']' | |
| print 'command=copy' | |
| print 'icon=' | |
| print 'subtext=' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why not submit it back as a PR?