@cmt+アールエフCエイト ツー ツー+nips-十三+
This commit is contained in:
parent
49106b601a
commit
0c708b3ccc
2 changed files with 22 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
*.log
|
||||
*.pyc
|
||||
__pycache__/
|
||||
geckodriver
|
||||
|
|
28
translate.py
28
translate.py
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import readline
|
||||
# import urllib.parse
|
||||
from selenium import webdriver
|
||||
|
||||
browser = webdriver.Firefox()
|
||||
|
@ -11,21 +12,34 @@ _lang_conf = {
|
|||
'chinese-tradional': 'zh-TW',
|
||||
'chinese-simplified': 'zh-CN',
|
||||
'hindi': 'hi'
|
||||
}; TRP_CONSTRUCT = "https://DOMAIN.translate.goog/PATH/?_x_tr_sl=auto&_x_tr_tl=[TRL]&_x_tr_hl=en-US&_x_tr_pto=wapp"
|
||||
neTRP_CONSTRUCT = TRP_CONSTRUCT.replace('[TRL]', 'ne')
|
||||
enTRP_CONSTRUCT = TRP_CONSTRUCT.replace('[TRL]', 'en') # yet another globals object !
|
||||
}; TRP_CONSTRUCT = "https://DOMAIN.translate.goog/PATH/?_x_tr_sl=auto&_x_tr_tl=TRL&_x_tr_hl=en-US&_x_tr_pto=wapp"
|
||||
_TRP_CONSTRUCT = "https://DOMAIN.translate.goog/PATH?_x_tr_sl=auto&_x_tr_tl=TRL"
|
||||
# TODO: Language selection (while keeping up Nepali as default)
|
||||
|
||||
# TODO: URL-parsing
|
||||
url = input("Enter URL you wish to translate: ")
|
||||
_lang = _lang_conf['nepali']
|
||||
_TRP_CONSTRUCT = _TRP_CONSTRUCT.replace('TRL', _lang)
|
||||
|
||||
remote_domain = url.split('://')[1].split('/')[0]
|
||||
#print('-'.join(remote_domain.split('.')[1:]))
|
||||
#print(remote_domain.replace('.', '-'))
|
||||
|
||||
remote_path = '/'.join(url.split('/')[3:])
|
||||
rDUri = remote_domain.replace('.', '-')
|
||||
#print(remote_path)
|
||||
|
||||
rDUri = remote_domain.replace('-', '--')
|
||||
rDUri = rDUri.replace('.', '-')
|
||||
|
||||
rUrl = _TRP_CONSTRUCT.replace('DOMAIN', rDUri).replace('PATH', remote_path)
|
||||
if '?' in remote_path:
|
||||
remote_path = remote_path.split('?')[0]
|
||||
remote_URL_query = ''.join(url.split('?')[1:])
|
||||
rUrl = neTRP_CONSTRUCT.replace('DOMAIN', rDUri).replace('PATH', remote_path) + '&' + remote_URL_query
|
||||
else:
|
||||
rUrl = neTRP_CONSTRUCT.replace('DOMAIN', rDUri).replace('PATH', remote_path)
|
||||
rUrl = _TRP_CONSTRUCT.replace('DOMAIN', rDUri).replace('PATH', remote_path) + '&' + remote_URL_query
|
||||
|
||||
# print(rUrl)
|
||||
|
||||
print("Executing: " + rUrl + " \n\twithin #DOM .")
|
||||
browser.get(rUrl)
|
||||
# browser.
|
||||
browser.execute_script('''document.querySelector('iframe').style.display = "none";document.querySelector('iframe').remove()''')
|
||||
|
|
Loading…
Reference in a new issue