Skip to content
Snippets Groups Projects
Commit 4abb783c authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

set working directory

parent 684a616b
No related branches found
No related tags found
No related merge requests found
......@@ -39,43 +39,54 @@ source lq-w-extr/bin/activate
### 3. Install dependencies
```
```bash
pip install -r requirements.txt
```
_Since `wiktextract` and its dependency `wikitextprocessor` are not regularly published as a Python package, it's a challenge to fix them to a specific version. From `requirements.txt`, the latest version will always be installed. Attention: This might mean that after reinstalling, the output schema of `wiktextract` might have slightly changed._
### 4. Load templates from dump files
### 4. Congigure server
[config.py](https://gitlab.liris.cnrs.fr/lex-game/live-query-wiktextract/-/blob/main/src/config.py) contains :
* server settings (`host`, `port` and `debug` (boolean))
* supported wiktionary language
* working directory (this can be useful if the server is launched by another server using absolute paths to handle virtual environment)
### 5. Load templates from dump files
Run the script `src/load_dumps.py` to load the most recent dumpfile (for each [supported language](https://gitlab.liris.cnrs.fr/lex-game/live-query-wiktextract/-/blob/main/src/config.py#L5)) into an sqlite database that will be used by `wiktextract`.
Run the script `src/load_dumps.py` to load the most recent dumpfile (for each [supported wiktionary language](https://gitlab.liris.cnrs.fr/lex-game/live-query-wiktextract/-/blob/main/src/config.py#L5)) into an sqlite database that will be used by `wiktextract`.
```
```bash
python src/load_dumps.py
```
### 5. Start flask app
### 6. Start flask app
```
```bash
flask --app src/app.py run
```
You might want to use to ensure flask runs in your currently active virtual environment.
```
```bash
python -m flask --app src/app.py run
```
You can run directly in your virtual environment using absolute paths (in case another server needs to launch this one in one command), example of such command
```bash
sh -c nohup /var/www/live-query-wiktextract/lq-w-extr/bin/python3 /var/www/live-query-wiktextract/src/app.py
```
## Using Docker
Alternatively the app can also be containerized using Docker. You still have to provide the dump files in `dumps/`.
Then performs the two steps:
### 2. Build image
### 1. Build image
```
docker build -t live-query-wiktextract .
```
### 3. Run image
### 2. Run image
```
docker run -p 5000:80 live-query-wiktextract
......
......@@ -4,6 +4,17 @@ from flask_cors import CORS
import config
from wiktextract_wrapper import Wiktextract
# import logging
# logging.basicConfig(filename='flask.log', level=logging.DEBUG)
# setting working directory
import os
try:
if config.wd != None:
os.chdir(config.wd)
except Exception as e:
print(f"Working directory for wiktextract_live_query was not specified (config.wd), setting ignored\n{e}")
app = Flask(__name__)
CORS(app)
......@@ -46,6 +57,7 @@ def search(lang, word):
@app.route("/search/<wiktlang>/<wordlang>/<word>/<format>", methods=["GET"])
def search_and_format(wiktlang, wordlang, word, format):
# app.logger.info('Received a request from /search/<wiktlang>/<wordlang>/<word>/<format>')
if wiktlang not in config.supported_wiktlangs:
return jsonify({"error": f"Language {wiktlang} not supported"}), 400
wiktextractor = Wiktextract(wiktlang, wordlang)
......@@ -88,3 +100,4 @@ def search_and_format(wiktlang, wordlang, word, format):
if __name__ == "__main__":
app.run(host=config.host, port=config.port, debug=config.debugging)
# app.run(host='0.0.0.0')
host = "0.0.0.0"
port = 80
debugging = True
port = 5000
debugging = False #True
supported_wiktlangs = ["en", "fr", "de", "es", "ru"]
wd = "/var/www/live-query-wiktextract"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment