Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Technik
protocol-translation-live
Commits
9a4292d4
Commit
9a4292d4
authored
Apr 05, 2022
by
Jakob Lerch
Browse files
add init.py
parent
406fb2c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
protocol_translation/__init__.py
0 → 100644
View file @
9a4292d4
protocol_translation/__main__.py
0 → 100644
View file @
9a4292d4
import
json
import
time
from
configparser
import
ConfigParser
from
pathlib
import
Path
import
requests
import
utils
from
pad
import
Etherpad
,
HedgedocNote
,
Pad
# TODO: scheint nur bei fem-instanz zu funktionieren. bei libretranslate.de kackt das ab
# TODO: auch kompatibel mit deepl machen
# TODO: besseren algorithmus für die übersetzung ausdenken (working sets)
if
__name__
==
"__main__"
:
# read config
# ..read api keys
api_keys
=
ConfigParser
()
api_keys
.
read
(
"api_keys.conf"
)
# ..read everything else
config
=
ConfigParser
()
config
.
read
(
"config.conf"
)
# create src pad
src_conf
=
config
[
"source"
]
src_pad
:
Pad
if
src_conf
[
"kind"
]
==
"hedgedoc"
:
src_pad
=
HedgedocNote
(
src_conf
[
"url"
])
elif
src_conf
[
"kind"
]
==
"etherpad"
:
src_pad
=
Etherpad
(
src_conf
[
"url"
],
api_keys
[
"default"
][
"etherpad_key"
])
else
:
raise
ValueError
(
"config.conf: 'kind' in [source] is not valid"
)
src_lang
=
src_conf
[
"language"
]
# create dst pad
# ..other than etherpad is not supported as destination yet
dst_conf
=
config
[
"destination"
]
dst_pad
=
Etherpad
(
dst_conf
[
"url"
],
api_keys
[
"default"
][
"etherpad_key"
])
dst_lang
=
dst_conf
[
"language"
]
# do translation
# ..initial translation
dst_pad
.
write
(
utils
.
translate_src_to_dst
(
url
=
config
[
"main"
][
"libretranslate_service_url"
],
src_string
=
src_pad
.
read
(),
src_lang
=
src_lang
,
dst_lang
=
dst_lang
,
api_key
=
api_keys
[
"default"
][
"libretranslate_key"
]))
# ..further translation
while
True
:
# TODO: think of algorithm / try naiv method, if this works, do it
dst_pad
.
write
(
utils
.
translate_src_to_dst
(
url
=
config
[
"main"
][
"libretranslate_service_url"
],
src_string
=
src_pad
.
read
(
),
src_lang
=
src_lang
,
dst_lang
=
dst_lang
,
api_key
=
api_keys
[
"default"
][
"libretranslate_key"
]))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment