From 3e18fc3f688847c332b3aa42f5876e9765da5a4d Mon Sep 17 00:00:00 2001 From: MarkEEaton Date: Wed, 15 Sep 2021 09:53:44 -0400 Subject: [PATCH] remove unnecessary async --- cloud_function.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cloud_function.py b/cloud_function.py index 110419e..1e49f28 100644 --- a/cloud_function.py +++ b/cloud_function.py @@ -3,8 +3,7 @@ import spacy import asyncio from flask import Response -from aiohttp import ClientSession as Session -from gcloud.aio.storage import Storage +from google.cloud import storage nlp = spacy.load("en_core_web_md", disable=["tagger", "parser", "ner", "lemmatizer"]) @@ -15,19 +14,21 @@ async def doaj_trio(request): data = json.loads(string_data) assert data["t"] == os.environ['token'] - async with Session() as session: - storage = Storage(session=session) - bucket = storage.get_bucket(os.environ['bucket']) - blob = data["f"] - print(blob) - blob_object = await bucket.get_blob(blob) - raw_data = await blob_object.download() - journal_nlp = nlp(str(raw_data)[:100000]) - user_nlp = nlp(data["d"]) - sim = user_nlp.similarity(journal_nlp) - return str(sim) + client = storage.Client() + bucket = client.get_bucket(os.environ['bucket']) + + blob = data["f"] + print(blob) + + blob_object = bucket.get_blob(blob) + raw_data = blob_object.download_as_text() + journal_nlp = nlp(str(raw_data)[:100000]) + user_nlp = nlp(data["d"]) + sim = user_nlp.similarity(journal_nlp) + return str(sim) except (AssertionError, KeyError, json.decoder.JSONDecodeError): return Response("403 Forbidden", status=403, mimetype="text/plain") except: + raise return Response("500 Error", status=500, mimetype="text/plain")