mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Starting work on librarian headless mode
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
habanero
|
habanero
|
||||||
waitress
|
waitress
|
||||||
flask
|
flask[async]
|
||||||
@@ -68,7 +68,7 @@ def producer(out_q, control_q, filename, _logger):
|
|||||||
|
|
||||||
|
|
||||||
# IMPORTANT!!! ONLY ONE CONSUMER THREAD AS WE ARE NOT PUTTING SENTINELS BACK
|
# IMPORTANT!!! ONLY ONE CONSUMER THREAD AS WE ARE NOT PUTTING SENTINELS BACK
|
||||||
def consumer(in_q, control_q, doi, live_results, result_list, control_dict, _logger):
|
def consumer(in_q, control_q, doi, live_results, result_list, control_dict, no, _logger):
|
||||||
"""
|
"""
|
||||||
Consumes items from an input queue and checks if DOI exists in the live results list.
|
Consumes items from an input queue and checks if DOI exists in the live results list.
|
||||||
|
|
||||||
@@ -79,6 +79,7 @@ def consumer(in_q, control_q, doi, live_results, result_list, control_dict, _log
|
|||||||
live_results (list): List to store the search results.
|
live_results (list): List to store the search results.
|
||||||
_logger: Logger object for logging.
|
_logger: Logger object for logging.
|
||||||
"""
|
"""
|
||||||
|
_logger.info("Consumer thread started:%s", no)
|
||||||
for item in doi:
|
for item in doi:
|
||||||
result_list.append({"DOI": item[0], "exists": False, "data": item[1]})
|
result_list.append({"DOI": item[0], "exists": False, "data": item[1]})
|
||||||
while True:
|
while True:
|
||||||
@@ -120,9 +121,9 @@ def search_for_doi(doi, live_results, _logger):
|
|||||||
threads = []
|
threads = []
|
||||||
work_q = Queue(maxsize=WORK_Q_SIZE)
|
work_q = Queue(maxsize=WORK_Q_SIZE)
|
||||||
control_q = Queue()
|
control_q = Queue()
|
||||||
for _ in range (1, len(doi)//1000+1):
|
for i in range (0, (len(doi)//1000)+2):
|
||||||
t_cons = Thread(
|
t_cons = Thread(
|
||||||
target=consumer, args=(work_q, control_q, doi, live_results, result_list, control_dict, _logger)
|
target=consumer, args=(work_q, control_q, doi, live_results, result_list, control_dict, i, _logger)
|
||||||
)
|
)
|
||||||
_logger.info("Consumer thread created")
|
_logger.info("Consumer thread created")
|
||||||
threads.append(t_cons)
|
threads.append(t_cons)
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
|
from logging import handlers
|
||||||
|
import requests
|
||||||
|
|
||||||
|
MAIN_BOT_ADDRESS = "http://192.168.1.191:5000"
|
||||||
|
SEND_RESULTS = "/conjurer"
|
||||||
|
|
||||||
|
async def send_results():
|
||||||
|
logger = logging.getLogger()
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
h1 = handlers.RotatingFileHandler(
|
||||||
|
filename="D:\\logs\\librarian.log",
|
||||||
|
encoding="utf-8",
|
||||||
|
mode="a",
|
||||||
|
maxBytes=6 * 1024 * 1024,
|
||||||
|
backupCount=6,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.addHandler(h1)
|
||||||
|
|
||||||
|
with open("s_results.json", "r+", encoding="utf-8") as s_file:
|
||||||
|
try:
|
||||||
|
database = json.load(s_file)
|
||||||
|
except JSONDecodeError:
|
||||||
|
pass
|
||||||
|
result = database["affd0dbc-e2c8-4173-b678-4103c0866495"]
|
||||||
|
result = {"affd0dbc-e2c8-4173-b678-4103c0866495":result}
|
||||||
|
|
||||||
|
coroutine = asyncio.to_thread(
|
||||||
|
requests.post,
|
||||||
|
f"{MAIN_BOT_ADDRESS}{SEND_RESULTS}",
|
||||||
|
json=result,
|
||||||
|
timeout=360,
|
||||||
|
)
|
||||||
|
logger.info("SENT")
|
||||||
|
result = await coroutine
|
||||||
|
logger.info(result.status_code)
|
||||||
|
logger.info("SEND CONFIRMED")
|
||||||
|
async def main():
|
||||||
|
await send_results()
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
Reference in New Issue
Block a user