Skip to content

Commit

Permalink
Redirect if text query param missing (#20)
Browse files Browse the repository at this point in the history
* Redirect if text query param missing

* Update __init__.py

Co-authored-by: Aaron Wislang <asw101@users.noreply.github.com>
  • Loading branch information
ibidani and asw101 authored Jul 10, 2020
1 parent ddc8298 commit 795ae72
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 4-azure-functions-python-vscode/sentiment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
def main(req: func.HttpRequest) -> func.HttpResponse:
analyzer = SentimentIntensityAnalyzer()
text = req.params.get("text")
if text is None:
return func.HttpResponse(status_code=302, headers={"Location":req.url+"?text=I+Love+PyCon"})
scores = analyzer.polarity_scores(text)
sentiment = "positive" if scores["compound"] > 0 else "negative"
return func.HttpResponse(sentiment)


0 comments on commit 795ae72

Please sign in to comment.