Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
remove unnecessary async
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEEaton authored Sep 15, 2021
1 parent a0146ce commit 3e18fc3
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions cloud_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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")

0 comments on commit 3e18fc3

Please sign in to comment.