New function

This commit is contained in:
Alex Ellis
2017-04-22 17:28:00 -05:00
parent 274bf31927
commit 2e9e88b3b7
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,17 @@
FROM python:2.7-alpine
RUN pip install textblob
RUN python -m textblob.download_corpora
ADD https://github.com/alexellis/faas/releases/download/0.5.1-alpha/fwatchdog /usr/bin
RUN chmod +x /usr/bin/fwatchdog
WORKDIR /root/
COPY handler.py .
ENV fprocess="python handler.py"
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
CMD ["fwatchdog"]

View File

@ -0,0 +1,6 @@
#!/bin/sh
echo "Building functions/sentimentanalysis"
docker build -t functions/sentimentanalysis .

View File

@ -0,0 +1,17 @@
import sys
from textblob import TextBlob
def get_stdin():
buf = ""
for line in sys.stdin:
buf = buf + line
return buf
if(__name__ == "__main__"):
st = get_stdin()
blob = TextBlob(st)
out =""
for sentence in blob.sentences:
out = out + "Polarity: " + str(sentence.sentiment.polarity) + " Subjectivity: " + str(sentence.sentiment.subjectivity) + "\n"
print(out)