#1 wik / wik meaning / etym
#2 wikEn / wik meaning / etym
#3 wikRu / wik meaning / wikEtym, external etym
#4 reverso / wik meaning / wikEtym, external etym
#7 wikEn / wik meaning / wikEtym
#9 wikEn / wik meaning / wikEtym
import lxml
import xml.etree.ElementTree
from openpyxl import load_workbook
import requests
from openpyxl import Workbook
from openpyxl.utils import get_column_letter
import keyboard
import webbrowser
import pyperclip
import time
import ctypes
wb = load_workbook(filename = 'deneme.xlsx')
sheet_ranges = wb['Sheet1']
def remove_html_markup(s):
tag = False
quote = False
out = ""
for c in s:
if c == '<' and not quote:
tag = True
elif c == '>' and not quote:
tag = False
elif (c == '"' or c == "'") and tag:
quote = not quote
elif not tag:
out = out + c
return out
def remove_accent(word):
out=""
for a in word:
if not(a=="́" or a=="." or a=="," or a==";" or a=="?" or a=="\"" or a=="\'" or a==":" or a=="\n" or a=="«"or a=="»"):
out=out+a
return out
def wordmeaning(mode,word):
if mode==1:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("English"):len(b)]
b=b[b.find("
"):len(b)]
beginning = b.find("- ")
end = b.find("
")
b=b[beginning:end]
c=remove_html_markup(b)
if mode==2:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Russian"):len(b)]
b=b[b.find(""):len(b)]
beginning = b.find("- ")
end = b.find("
")
b=b[beginning:end]
c=remove_html_markup(b)
if mode==3:
x = requests.get('https://ru.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Значение"):len(b)]
a = remove_html_markup(b)
beginning = a.find("[править]")
end = a.find("◆")
c=a[beginning+9:end]
if mode==4:
x = requests.get('https://ru.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Значение"):len(b)]
a = remove_html_markup(b)
beginning = a.find("[править]")
end = a.find("◆")
c=a[beginning+9:end]
if mode==7:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Latin"):len(b)]
b=b[b.find(""):len(b)]
beginning = b.find("- ")
end = b.find("
")
b=b[beginning:end]
c=remove_html_markup(b)
if mode==9:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Ancient Greek"):len(b)]
b=b[b.find(""):len(b)]
beginning = b.find("- ")
end = b.find("
")
b=b[beginning:end]
c=remove_html_markup(b)
return c
def setmode(mode):
while mode==0:
for a in range(0,10):
if keyboard.is_pressed(str(a)) * (mode != a):
mode=a
return mode
def modeWordTUrl(mode,word):
#1:EngWik #2EngRusWik #3RusWik #4RusReverso #7LatWik #8LatPers #9GreWik
if mode == 1:
return 'https://en.wiktionary.org/wiki/'+word+'#English'
if mode == 2:
return 'https://en.wiktionary.org/wiki/'+word+'#Russian'
if mode == 3:
return 'https://ru.wiktionary.org/wiki/'+word+'#Русский'
if mode == 4:
return 'https://context.reverso.net/translation/russian-english/'+word
if mode == 7:
return 'https://en.wiktionary.org/wiki/'+word+'#Latin'
if mode == 9:
return 'https://en.wiktionary.org/wiki/'+word+'#Ancient Greek'
def dictionaryform(mode,word):
#2:ru 7:lat 9:gre
if mode==2 or mode==3 or mode==4 or mode==5 or mode==6 :
x = requests.get('https://conjugator.reverso.net/conjugation-russian-verb-'+word+'.html')
b=x.text
b=b[b.find(""):len(b)]
beginning = b.find("tooltip")
end = b.find("")
c=b[beginning+30:end]
if mode==7:
x = requests.get('http://www.perseus.tufts.edu/hopper/morph?l='+word+'&la=la')
b=x.text
beginning = b.find("")
c=b[beginning+15:end]
if mode==9:
x = requests.get('http://www.perseus.tufts.edu/hopper/morph?l='+word+'&la=greek')
b=x.text
beginning = b.find("")
c=b[beginning+18:end]
return c
def etymology(mode,word):
if mode==1:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("")
end = b.find("")
b=b[beginning:end]
c=remove_html_markup(b)
if mode==2 or mode==3 or mode==4 or mode==5 or mode==6:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Russian"):len(b)]
b=b[b.find("")
end = b.find("")
b=b[beginning:end]
c=remove_html_markup(b)
x = requests.get('https://ru.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Этимология"):len(b)]
beginning = b.find("")
end = b.find("
")
c=c+"----"+remove_html_markup(b[beginning:end])
if mode==7:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Latin"):len(b)]
b=b[b.find("")
end = b.find("")
b=b[beginning:end]
c=remove_html_markup(b)
if mode==9:
x = requests.get('https://en.wiktionary.org/wiki/' + word)
b=x.text
b=b[b.find("Ancient_Greek"):len(b)]
b=b[b.find("")
end = b.find("")
b=b[beginning:end]
c=remove_html_markup(b)
return c
i=1
a='A'+ str(i)
b=0
mode=0
mode=setmode(mode)
ctypes.windll.user32.MessageBoxW(0, "Mode set", str(mode), 1)
while 1:
if keyboard.is_pressed('ctrl') * keyboard.is_pressed('c') * keyboard.is_pressed('k') :
time.sleep(0.15)
webbrowser.open( 'https://translate.google.com.tr/?hl=tr&sl=auto&tl=en&text='+ pyperclip.paste() +'&op=translate' , new=0)
while keyboard.is_pressed('ctrl') * keyboard.is_pressed('c'):
time.sleep(0.001)
elif keyboard.is_pressed('ctrl') * keyboard.is_pressed('c') * (not (keyboard.is_pressed('l'))) * (not (keyboard.is_pressed('k'))):
while sheet_ranges[a].value is not None:
i=i+1
a='A'+ str(i)
b='B'+ str(i)
c='C'+ str(i)
d='D'+ str(i)
time.sleep(0.15)
word=remove_accent( pyperclip.paste() )
sheet_ranges[a]=word
if keyboard.is_pressed('u'):
print("word: "+word)
difo=dictionaryform(mode,word)
print("difo: "+difo)
difo=remove_accent(difo)
print("difo without accent:"+difo)
else:
difo=word
print("your word is "+difo)
sheet_ranges[b]=difo
mean=wordmeaning(mode,difo)
sheet_ranges[c]=mean
etym=etymology(mode,difo)
sheet_ranges[d]=etym
print ("its meaning is: "+mean)
print ("its etymology is: "+etym)
webbrowser.open( modeWordTUrl(mode,difo) , new=0)
wb.save(filename = 'deneme.xlsx')
b=1
while keyboard.is_pressed('ctrl') * keyboard.is_pressed('c'):
time.sleep(0.001)