def record_callback(reply): if reply.category != record.FromServer: return if reply.client_swapped: print "* received swapped protocol data, cowardly ignored" return if not len(reply.data) or ord(reply.data[0]) < 2: # not an event return data = reply.data while len(data): event, data = rq.EventField(None).parse_binary_value(data, record_dpy.display, None, None) # deal with the event type if event.type == X.ButtonRelease: # get text pipe = os.popen("xclip -o") text = pipe.readline() pipe.readlines() #清空管道剩余部分 pipe.close() print "您选取的是: ", text text = text.strip('\r\n\x00').lower() if(gl.pre_text != text and text!=""): gl.pre_text = text url= "http://dict.youdao.com/search?q=" + text print url os.system("curl -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'") #获得网页(非代理) fusionyoudao.reconstruct() gl.homeurl="file://" + gl.resultdir #合成最终缓冲访问地址 window.load(gl.homeurl) window.show()
def record_callback(reply): if reply.category != record.FromServer: return if reply.client_swapped: print "* received swapped protocol data, cowardly ignored" return if not len(reply.data) or ord(reply.data[0]) < 2: # not an event return data = reply.data while len(data): event, data = rq.EventField(None).parse_binary_value(data, record_dpy.display, None, None) # deal with the event type if event.type == X.ButtonRelease: # get text pipe = os.popen("xclip -o") text = pipe.readline() pipe.readlines() #清空管道剩余部分 pipe.close() print "您选取的是: ", text text = text.strip('\r\n\x00').lower() if(gl.pre_text != text and text!=""): gl.pre_text = text if(False==os.path.exists(gl.cachedir)): os.system("mkdir \'" + gl.cachedir + "\'") os.system("touch \'" + gl.origindir + "\'") os.system("touch \'" + gl.resultdir + "\'") url= "http://dict.youdao.com/search?q=" + text print url os.system("curl -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'") #获得网页(非代理) fusionyoudao.reconstruct() gl.homeurl="file://" + gl.resultdir #合成最终缓冲访问地址 window.load(gl.homeurl) window.show()
def lookup(): pre_text="" text="" #监视history.txt变化 cmd = "tail -f " + gl.historydir if(gl.baseurl==""): gl.baseurl=gl.baseurlyoudao myfile=os.popen(cmd) while True: text=myfile.readline().strip('\r\n\x00') if (pre_text != text or gl.prebaseurl != gl.baseurl) and text != "" : # 或者不一定对lzt pre_text = text print gl.lock gl.prebaseurl = gl.baseurl url= gl.baseurl + text #合成地址 print url + "kkkkkkkkkkkk" #合成地址检测点1 #如果需要设置了代理取消"代理"行注释,并将"非代理"行注释掉 #代理相关参数在gl.py中设置proxyDict变量 if gl.proxyDict =={}: r = requests.get(url) #获得网页(非代理) else: r = requests.get(url, headers={'content-type':'text/plain'}, proxies=gl.proxyDict) #(代理) f_tar=open(gl.origindir,'w+') #缓存原始网页 print >>f_tar,r.text f_tar.close() os.system("echo \'"+ gl.downloadwait + "\' > cache/result.html") #清空最终缓冲增强程序稳健性 if(gl.baseurl==gl.baseurlyoudao): fusionyoudao.reconstruct() #区分聚合 if(gl.baseurl==gl.baseurlicb): fusionicb.reconstruct() gl.homeurl="file://" + gl.resultdir #合成最终缓冲访问地址 window.load(gl.homeurl) #加载最终缓冲内容到浏览器 window.show() #显示结果 gl.lock=0
def show_result(url) : res = urllib2.urlopen(gl.baseurl + gl.text) # 抓取网页 gl.source_html = res.read() res.close() fusionyoudao.reconstruct() # 得到result并重新架构html window.autoload() window.show()
def lookup(): pre_text = "" text = "" cmd = "tail -f " + gl.historydir if gl.baseurl == "": gl.baseurl = gl.baseurlyoudao myfile = os.popen(cmd) while True: text = myfile.readline().strip("\r\n\x00") if (pre_text != text or gl.prebaseurl != gl.baseurl) and text != "": pre_text = text gl.prebaseurl = gl.baseurl url = gl.baseurl + text # 合成地址 os.system("curl -s -o '" + gl.origindir + "' '" + url + "'") # 获得网页(非代理) fusionyoudao.reconstruct() # 区分聚合 gl.homeurl = "file://" + gl.resultdir # 合成最终缓冲访问地址 window.load(gl.homeurl) # 加载最终缓冲内容到浏览器 window.show() # 显示结果 gl.lock = 0
def run(self): pre_text = "" text = "" # 监视history.txt变化 cmd = "tail -f " + gl.historydir if(gl.baseurl == ""): gl.baseurl = gl.baseurlyoudao myfile = os.popen(cmd) while True: text = myfile.readline().strip('\r\n\x00') if (pre_text != text or gl.prebaseurl != gl.baseurl) and text != "" : # 或者不一定对lzt pre_text = text print gl.lock gl.prebaseurl = gl.baseurl url = gl.baseurl + text # 合成地址 print url + "kkkkkkkkkkkk" # 合成地址检测点1 # 使用curl进行网页下载 # 如果需要设置了代理取消"代理"行注释,并将"非代理"行注释掉 os.system("curl -s -o \'" + gl.origindir + "\' \'" + url + "\'") # 获得网页(非代理) # os.system("curl -s -o --socks5-hostname ip:port \'" + gl.origindir +"\' \'" + url+ "\'") #代理 # 使用python-requests进行网页下载,在debian中可以正常使用,考虑到其它系统的兼容性,改用curl # 如果需要设置了代理取消"代理"行注释,并将"非代理"行注释掉 # 代理相关参数在gl.py中设置proxyDict变量 # if gl.proxyDict =={}: # r = requests.get(url) #获得网页(非代理) # else: # r = requests.get(url, headers={'content-type':'text/plain'}, proxies=gl.proxyDict) #(代理) # f_tar=open(gl.origindir,'w+') #缓存原始网页 # print >>f_tar,r.text # f_tar.close() # os.system("echo \'"+ gl.downloadwait + "\' > cache/result.html") #清空最终缓冲增强程序稳健性 if(gl.baseurl == gl.baseurlyoudao): fusionyoudao.reconstruct() # 区分聚合 if(gl.baseurl == gl.baseurlicb): fusionicb.reconstruct() gl.homeurl = "file://" + gl.resultdir # 合成最终缓冲访问地址 # self.window.load(gl.homeurl) # 加载最终缓冲内容到浏览器 # self.window.show() # 显示结果 self.signal.emit(gl.homeurl) gl.lock = 0
def lookup(): pre_text = "" text = "" cmd = "tail -f " + gl.historydir if (gl.baseurl == ""): gl.baseurl = gl.baseurlyoudao myfile = os.popen(cmd) while True: text = myfile.readline().strip('\r\n\x00') if (pre_text != text or gl.prebaseurl != gl.baseurl) and text != "": pre_text = text gl.prebaseurl = gl.baseurl url = gl.baseurl + text #合成地址 os.system("curl -s -o \'" + gl.origindir + "\' \'" + url + "\'") #获得网页(非代理) fusionyoudao.reconstruct() #区分聚合 gl.homeurl = "file://" + gl.resultdir #合成最终缓冲访问地址 window.load(gl.homeurl) #加载最终缓冲内容到浏览器 window.show() #显示结果 gl.lock = 0
def lookup(): pre_text = "" text = "" #监视history.txt变化 cmd = "tail -f " + gl.historydir if (gl.baseurl == ""): gl.baseurl = gl.baseurlyoudao myfile = os.popen(cmd) while True: text = myfile.readline().strip('\r\n\x00') if (pre_text != text or gl.prebaseurl != gl.baseurl) and text != "": # 或者不一定对lzt pre_text = text print gl.lock gl.prebaseurl = gl.baseurl url = gl.baseurl + text #合成地址 print url + "kkkkkkkkkkkk" #合成地址检测点1 #使用curl进行网页下载 #如果需要设置了代理取消"代理"行注释,并将"非代理"行注释掉 os.system("curl -s -o \'" + gl.origindir + "\' \'" + url + "\'") #获得网页(非代理) #os.system("curl -s -o --socks5-hostname ip:port \'" + gl.origindir +"\' \'" + url+ "\'") #代理 #使用python-requests进行网页下载,在debian中可以正常使用,考虑到其它系统的兼容性,改用curl #如果需要设置了代理取消"代理"行注释,并将"非代理"行注释掉 #代理相关参数在gl.py中设置proxyDict变量 #if gl.proxyDict =={}: # r = requests.get(url) #获得网页(非代理) #else: # r = requests.get(url, headers={'content-type':'text/plain'}, proxies=gl.proxyDict) #(代理) #f_tar=open(gl.origindir,'w+') #缓存原始网页 #print >>f_tar,r.text #f_tar.close() #os.system("echo \'"+ gl.downloadwait + "\' > cache/result.html") #清空最终缓冲增强程序稳健性 if (gl.baseurl == gl.baseurlyoudao): fusionyoudao.reconstruct() #区分聚合 if (gl.baseurl == gl.baseurlicb): fusionicb.reconstruct() gl.homeurl = "file://" + gl.resultdir #合成最终缓冲访问地址 window.load(gl.homeurl) #加载最终缓冲内容到浏览器 window.show() #显示结果 gl.lock = 0
def record_callback(reply): if reply.category != record.FromServer: return if reply.client_swapped: print "* received swapped protocol data, cowardly ignored" return if not len(reply.data) or ord(reply.data[0]) < 2: # not an event return data = reply.data while len(data): event, data = rq.EventField(None).parse_binary_value( data, record_dpy.display, None, None) # deal with the event type if event.type == X.ButtonRelease: # get text global Alive pipe = os.popen("xclip -o") text = pipe.readline() pipe.readlines() #清空管道剩余部分 pipe.close() print "您选取的是: ", text text = text.strip('\r\n\x00').lower().strip() if (gl.pre_text != text and text != ""): gl.pre_text = text if (False == os.path.exists(gl.cachedir)): os.system("mkdir \'" + gl.cachedir + "\'") os.system("touch \'" + gl.origindir + "\'") os.system("touch \'" + gl.resultdir + "\'") if "%zh2enlj%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2enlj.html" gl.searchurl = gl.zh2enlj url = "" gl.func = "lj" elif "%zh2japlj%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2japlj.html" gl.searchurl = gl.zh2japlj url = "" gl.func = "lj" elif "%zh2kolj%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2kolj.html" gl.searchurl = gl.zh2kolj url = "" gl.func = "lj" elif "%zh2frlj%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2frlj.html" gl.searchurl = gl.zh2frlj url = "" gl.func = "lj" elif "%zh2en%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2en.html" gl.searchurl = gl.zh2en url = "" elif "%zh2jap%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2jap.html" gl.searchurl = gl.zh2jap url = "" elif "%zh2ko%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2ko.html" gl.searchurl = gl.zh2ko url = "" elif "%zh2fr%" in text: gl.homeurl = "file:///usr/share/openyoudao/zh2fr.html" gl.searchurl = gl.zh2fr url = "" elif "%index%" in text: gl.homeurl = "file:///usr/share/openyoudao/config.html" url = "" elif "%helps%" in text: gl.homeurl = "file:///usr/share/openyoudao/help.html" url = "" elif "%donate%" in text: gl.homeurl = "file:///usr/share/openyoudao/donate.html" url = "" elif "%exits%" in text: Alive = 0 else: url = gl.searchurl + text if url != "": os.system( "curl -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir + "\' \'" + url + "\'") #获得网页(非代理) fusionyoudao.reconstruct(gl.func) gl.homeurl = "file://" + gl.resultdir #合成最终缓冲访问地址 if Alive == 1: window.load(gl.homeurl) window.show()
def record_callback(reply): if reply.category != record.FromServer: return if reply.client_swapped: print "* received swapped protocol data, cowardly ignored" return if not len(reply.data) or ord(reply.data[0]) < 2: # not an event return data = reply.data while len(data): event, data = rq.EventField(None).parse_binary_value(data, record_dpy.display, None, None) # deal with the event type if event.type == X.ButtonRelease: # get text global Alive pipe = os.popen("xclip -o") text = pipe.readline() pipe.readlines() #清空管道剩余部分 pipe.close() print "您选取的是: ", text text = text.strip('\r\n\x00').lower().strip() if(gl.pre_text != text and text!=""): gl.pre_text = text if(False==os.path.exists(gl.cachedir)): os.system("mkdir \'" + gl.cachedir + "\'") os.system("touch \'" + gl.origindir + "\'") os.system("touch \'" + gl.resultdir + "\'") if "%zh2enlj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2enlj.html" gl.searchurl=gl.zh2enlj url = "" gl.func="lj" elif "%zh2japlj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2japlj.html" gl.searchurl=gl.zh2japlj url = "" gl.func="lj" elif "%zh2kolj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2kolj.html" gl.searchurl=gl.zh2kolj url = "" gl.func="lj" elif "%zh2frlj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2frlj.html" gl.searchurl=gl.zh2frlj url = "" gl.func="lj" elif "%zh2en%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2en.html" gl.searchurl=gl.zh2en url = "" elif "%zh2jap%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2jap.html" gl.searchurl=gl.zh2jap url = "" elif "%zh2ko%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2ko.html" gl.searchurl=gl.zh2ko url = "" elif "%zh2fr%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2fr.html" gl.searchurl=gl.zh2fr url = "" elif "%index%" in text: gl.homeurl="file:///usr/share/openyoudao/config.html" url = "" elif "%helps%" in text: gl.homeurl="file:///usr/share/openyoudao/help.html" url = "" elif "%donate%" in text: gl.homeurl="file:///usr/share/openyoudao/donate.html" url = "" elif "%exits%" in text: Alive=0 else: url= gl.searchurl + text if url !="": os.system("curl -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'") #获得网页(非代理) fusionyoudao.reconstruct(gl.func) gl.homeurl="file://" + gl.resultdir #合成最终缓冲访问地址 if Alive==1: window.load(gl.homeurl) window.show()
def record_callback(reply): if reply.category != record.FromServer: return if reply.client_swapped: print "* received swapped protocol data, cowardly ignored" return if not len(reply.data) or ord(reply.data[0]) < 2: # not an event return data = reply.data while len(data): event, data = rq.EventField(None).parse_binary_value(data, record_dpy.display, None, None) # deal with the event type if event.type == X.ButtonRelease: # get text global Alive pipe = os.popen("xclip -o") text = pipe.readline().strip('\r\n\x00 ').lower() #如果首行以连字符'-'结尾,则去掉'-'和空格接次行,否则加空格接次行 if text.endswith('-'): text = text.strip(' -') + pipe.readline().strip('\r\n\x00 ').lower() else: text = text + ' ' + pipe.readline().strip('\r\n\x00 ').lower() text = text.strip() pipe.readlines() #清空管道剩余部分 pipe.close() print "您选取的是: ", text if(gl.pre_text != text and text!=""and gl.lock=="0" or text=="%lock%"): url = "" gl.pre_text = text if(False==os.path.exists(gl.cachedir)): os.system("mkdir \'" + gl.cachedir + "\'") for dir in (gl.origindir,gl.resultdir,gl.historydir,gl.keyworddir): if(False==os.path.exists(dir)): os.system("touch \'" + dir + "\'") #youdao if "%zh2enlj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2enlj.html" gl.searchurl=gl.zh2enlj url = "" gl.func="lj" gl.Dict="youdao" gl.title="汉英例句" elif "%zh2japlj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2japlj.html" gl.searchurl=gl.zh2japlj url = "" gl.func="lj" gl.Dict="youdao" gl.title="汉日例句" elif "%zh2kolj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2kolj.html" gl.searchurl=gl.zh2kolj url = "" gl.func="lj" gl.Dict="youdao" gl.title="汉韩例句" elif "%zh2frlj%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2frlj.html" gl.searchurl=gl.zh2frlj url = "" gl.func="lj" gl.Dict="youdao" gl.title="汉法例句" elif "%zh2en%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2en.html" gl.searchurl=gl.zh2en url = "" gl.Dict="youdao" gl.title="汉英互译" elif "%zh2jap%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2jap.html" gl.searchurl=gl.zh2jap url = "" gl.Dict="youdao" gl.title="汉日互译" elif "%zh2ko%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2ko.html" gl.searchurl=gl.zh2ko url = "" gl.Dict="youdao" gl.title="汉韩互译" elif "%zh2fr%" in text: gl.homeurl="file:///usr/share/openyoudao/zh2fr.html" gl.searchurl=gl.zh2fr url = "" gl.Dict="youdao" gl.title="汉法互译" #config elif "%index%" in text: gl.homeurl="file:///usr/share/openyoudao/config.html" url = "" gl.title="有道首页" elif "%helps%" in text: gl.homeurl="file:///usr/share/openyoudao/help.html" url = "" gl.title="使用说明" elif "%goslate%" in text: gl.homeurl="file:///usr/share/openyoudao/goslate.html" url = "" gl.Dict="google" gl.title="谷歌翻译" elif "%donate%" in text: gl.homeurl="file:///usr/share/openyoudao/donate.html" url = "" gl.title="捐赠页面" elif "%expand%" in text: gl.homeurl="file:///usr/share/openyoudao/expand.html" url = "" gl.title="展开选项" elif "%history%" in text: gl.homeurl= "file://" + gl.historydir if Alive==1: his_tar=open(gl.historydir,'w') print >> his_tar,"<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>History</title></head><body><p>%s %s</p>"%("%index%","%expand%") keyword=open(gl.keyworddir,'r') print >> his_tar,keyword.read() print >> his_tar,"</body></html>" his_tar.close() keyword.close() url = "" gl.title="取词历史" elif "%lock%" in text: if gl.lock=="0": gl.lock="1" gl.homeurl="file:///usr/share/openyoudao/lock.html" gl.title="锁定取词" else: gl.lock="0" gl.homeurl="file:///usr/share/openyoudao/unlock.html" gl.title="取词解锁" url = "" elif "%exits%" in text: Alive=0 else: url= gl.searchurl + text if url !="": if Alive==1: k_tar=open(gl.keyworddir,'a') print >> k_tar,"<p>%s</p>" % text k_tar.close() #fp = file(gl.keyworddir) #lines = [] #for line in fp: # 内置的迭代器, 效率很高 # lines.append(line) #fp.close() #lines.insert(0, "<p>%s</p>" % text) # 在第二行插入 #s = '\n'.join(lines) #fp = file(gl.keyworddir, 'w') #fp.write(s) #fp.close() #[google youdao] if gl.Dict=="google": gs = goslate.Goslate() gl.lang=gs.detect(text) g_tar=open(gl.googledir,'w+') if gl.lang=='zh-CN': basehtml="<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>Google Translate</title></head><body><p>Source Language: %s</p><p>Target Language : %s</p><p>Selected Text : %s</p><p>Target Text : %s</p><p>%s %s</p></body></html>"%(gl.lang,'en',text,gs.translate(text, 'en'),"%index%","%expand%") else: basehtml="<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>Google Translate</title></head><body><p>Source Language: %s</p><p>Target Language : %s</p><p>Selected Text : %s</p><p>Target Text : %s</p><p>%s %s</p></body></html>"%(gl.lang,'zh-CN',text,gs.translate(text, 'zh-CN'),"%index%","%expand%") print >> g_tar,basehtml g_tar.close() gl.homeurl= "file://" + gl.googledir if gl.Dict=="youdao": os.system("curl -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'") #获得网页(非代理) fusionyoudao.reconstruct(gl.func) gl.homeurl="file://" + gl.resultdir #合成最终缓冲访问地址 if Alive==1: window.settitle(gl.title) window.load(gl.homeurl) window.show()