add logging

This commit is contained in:
2023-02-23 22:06:49 +01:00
parent ed610970cb
commit ef6074eaa9
4 changed files with 20 additions and 4 deletions

9
Dockerfile_search Normal file
View File

@@ -0,0 +1,9 @@
from python:3.8
workdir /srv
RUN pip3 install setuptools_scm
RUN pip3 install elasticsearch
COPY searching ./searching
COPY test_search.py .
CMD python3 test_search.py

View File

@@ -1,2 +1,3 @@
docker build -t docker.fet.at/andis_scrapy:0.1.2 .
docker build -t docker.fet.at/andis_index:0.1.2 -f Dockerfile_index .
docker build -t docker.fet.at/andis_index:0.1.2 -f Dockerfile_index .
docker build -t docker.fet.at/andis_search:0.1.3 -f Dockerfile_search .

View File

@@ -4,6 +4,7 @@
import os
from elasticsearch import Elasticsearch, helpers
import contextlib
import logging
ELASTIC_HOST = os.environ.get("ELASTIC_HOST","http://localhost:9200")
ELASTIC_PASSWORD = os.environ.get("ELASTIC_PASSWORD","*l9qNGoojiCC4n9KcZhj")
ELASTIC_QUERY = os.environ.get("ELASTIC_QUERY","Anwesend")
@@ -13,6 +14,7 @@ ELASTIC_INDEX = os.environ.get("ELASTIC_INDEX","legacy")
# Verbinde mit Client
@contextlib.contextmanager
def es_client():
logging.debug(f"ELASIC HOST:%s" % ELASTIC_HOST)
client = Elasticsearch(ELASTIC_HOST, verify_certs=False, basic_auth=('elastic', ELASTIC_PASSWORD))
yield client
client.close()
@@ -48,6 +50,7 @@ def es_search(query:str):
if __name__ =="__main__":
resp = es_search(ELASTIC_QUERY)
logging.info(f"Found %d recorts in hits" % resp["hits"]["hits"])
for hit in resp["hits"]["hits"]:
print(f"\n\n%s\n%s\n%s - %s" % (
hit.get("_source",{}).get("url",""),

View File

@@ -1,13 +1,16 @@
import os
from elasticsearch import Elasticsearch, helpers
from searching import es_search, es_client
from searching import es_search
ELASTIC_QUERY = os.environ.get("ELASTIC_QUERY","Anwesend")
import logging
#for hit in resp["hits"]["hits"]:
logging.basicConfig(level=logging.DEBUG)
#for hit in resp["hits"]["hits"]: q
# print(hit)
if __name__ =="__main__":
logging.debug(f"searching with query: %s\n" % ELASTIC_QUERY)
resp = es_search(ELASTIC_QUERY)
for hit in resp["hits"]["hits"]:
print(f"\n\n%s\n%s\n%s - %s" % (