linux shell翻译英文脚本

#!/bin/bash
curl -G -d "word=$1&a=getWordMean&c=search" http://www.iciba.com/index.php|grep word_mean > a.txt
cat ~/a.txt |while read LINE
do
    a=${LINE#*word_mean}
    expr substr "$a" 3 40
done

 

保存为ts.sh

菜鸟英文差,自写了个简单翻译的脚本。

 

用法:

 sh ts.sh 要翻译的词

 

 

补充一下 翻译英文的话 pip install iSearch 

s 要翻译的单词 可以翻译 英文

 

 

----------------2017年12月12日18:17:28

 

经过研究 改进之前写的trans脚本    支持中英文翻译

 

#!/bin/bash/env python
#-*- coding:utf-8 -*-

import requests
import re
import json 
import sys 

reload(sys)
sys.setdefaultencoding('utf8')

user_input      = sys.argv[1]
search_rq       = requests.get ('http://www.iciba.com/index.php', {'word' : user_input, 'a' : 'getWordMean', 'c' : 'search'})
search_rq_text  = search_rq.text
search_rq_obj   = json.loads (search_rq_text)
words_mean      = search_rq_obj['baesInfo']['symbols'][0]['parts'][0]['means']
sentences_mean  = search_rq_obj['sentence']

input_highlight = ['\033[33;35m ', ' \033[0m']

print "\033[43;35m 查询到的翻译: \033[0m \n"

for word in words_mean :
    print "\033[39;31m %s \033[0m \n" % word

print "\033[43;35m 查询到的短语: \033[0m \n"

for sentence in sentences_mean :
    print "\033[39;31m %s \033[0m \n" % sentence['Network_en']
    print "\033[39;31m %s \033[0m \n" % sentence['Network_cn'].replace (user_input, input_highlight[0] + user_input + input_highlight[1])


效果:

 

 

2017年12月13日11:16:40   

python 一大串的命令太麻烦      简化一下

/usr/local/bin/showme  (记得chomd755加权限哦)

 

#!/bin/bash

python /home/vagrant/trans.py $1


效果:

 

 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值