Skip to content

Instantly share code, notes, and snippets.

@ly0
Created April 11, 2014 11:56
Show Gist options
  • Select an option

  • Save ly0/10462163 to your computer and use it in GitHub Desktop.

Select an option

Save ly0/10462163 to your computer and use it in GitHub Desktop.
dict.py + wbdict.py + etym.py = dicts.py
#!/usr/bin/python
#coding=utf-8
import os
from Queue import Queue
import sys
import threading
def get_dict(word):
text = os.popen('dict %s' % word).read()
q.put('\n' + '-'*10 + '海词' + '-'*10 + '\n' + text)
def get_wbdict(word):
text = os.popen('wbdict %s' % word).read()
q.put('\n' + '-'*10 + '韦氏字典' + '-'*10 + '\n' + text)
def get_etym(word):
text = os.popen('etym %s' % word).read()
q.put('\n' + '-'*10 + '词源' + '-'*10 + '\n' + text)
word = sys.argv[1]
q = Queue()
_dict = threading.Thread(target=get_dict,args=(word,))
_wbdict = threading.Thread(target=get_wbdict,args=(word,))
_etym = threading.Thread(target=get_etym,args=(word,))
_dict.start()
_wbdict.start()
_etym.start()
for i in range(3):
while q.empty(): pass
print q.get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment