Commit 9a4292d4 authored by Jakob Lerch's avatar Jakob Lerch
Browse files

add init.py

parent 406fb2c1
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"]))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment