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

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",""),