Browse Source

Hebrew (#84)

* Add Hebrew transliteration via Dicta; add list options.

* Update README.

* Several Hebrew and general changes:

* Add capitalization options
* Move capitalization function to new "tools" module
* Use env file

* Add requests module.

* Remove camel_tools requirement.

* Make rabbinic the default style; add documentation for option type.

* Add Hebrew test strings.

* Fix Dicta input.

* WIP exception handling.

* Update requirements.

* Fix dotenv.

* WIP error handling.

* Use explicit JSON body.
Stefano Cossu 4 months ago
parent
commit
7e9bbf5e08
3 changed files with 12 additions and 3 deletions
  1. 1 0
      requirements.txt
  2. 2 3
      scriptshifter/hooks/hebrew/dicta_api.py
  3. 9 0
      scriptshifter/rest_api.py

+ 1 - 0
requirements.txt

@@ -1,4 +1,5 @@
 aksharamukha>=2.1,<2.2
+python-dotenv>=1.0,<2
 flask>=2.3,<2.4
 pyyaml>=6.0,<7
 uwsgi>=2.0,<2.1

+ 2 - 3
scriptshifter/hooks/hebrew/dicta_api.py

@@ -1,4 +1,3 @@
-from json import dumps
 from os import environ
 
 from requests import post
@@ -17,10 +16,10 @@ def s2r_post_config(ctx):
     ctx.warnings = []
     rsp = post(
             EP,
-            data=dumps({
+            json={
                 "data": ctx.src,
                 "genre": ctx.options.get("genre", DEFAULT_GENRE)
-            }))
+            })
     rsp.raise_for_status()
 
     rom = rsp.json().get("transliteration")

+ 9 - 0
scriptshifter/rest_api.py

@@ -7,6 +7,7 @@ from os import environ, urandom
 
 from flask import Flask, jsonify, render_template, request
 
+# from scriptshifter.exceptions import ApiError
 from scriptshifter.tables import list_tables, load_table
 from scriptshifter.trans import transliterate
 
@@ -31,6 +32,14 @@ def create_app():
 app = create_app()
 
 
+#@app.exception_handler(ApiError)
+#def handle_exception(request: Request, e: ApiError):
+#    return JSONResponse(
+#        content=e.to_json(),
+#        status_code=e.status_code
+#    )
+
+
 @app.route("/", methods=["GET"])
 def index():
     return render_template("index.html", languages=list_tables())