This commit is contained in:
Patrice 2019-07-06 18:02:00 +02:00
parent 5711e2b5f8
commit 2a36eaf00f
6 changed files with 23 additions and 68 deletions

View File

@ -1,17 +0,0 @@
FROM nginx:1.7
# Copy in conf files
COPY nginx.conf /etc/nginx/nginx.conf
COPY mime.types /etc/nginx/mime.types
COPY ssl.conf /etc/nginx/
COPY site.conf /etc/nginx/sites-enabled/
# COPY in certs
COPY ssl.crt /etc/nginx/ssl.crt
COPY ssl.key /etc/nginx/ssl.key
# Expose both the HTTP (80) and HTTPS (443) ports
EXPOSE 80 443
CMD ["nginx"]

View File

@ -13,4 +13,5 @@ COPY ./ /app
RUN python /app/nltkDown.py
WORKDIR /app
EXPOSE 5000
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app"]

View File

@ -2,7 +2,6 @@ import logging
import os
from flask import Flask
from flask_ask import Ask, request, session, question, statement
import yaml
from nltk.corpus import treebank
from textblob_de import TextBlobDE as TextBlob
import siteobj as site2
@ -69,13 +68,11 @@ def search_for(searchTerm):
else:
return question("Dazu konnte nichts gefunden werden. Möchten Sie nach etwas anderem Suchen?")
return question(response + " noch etwas?")
@ask.intent('News', mapping={'site': 'Site'}, default={'site': ''})
def news(site):
session.attributes["siteName"] = site
#site = util.get_session_value(session.attributes, "siteName")
if site is not None:
obj = get_site_obj(site)
@ -106,11 +103,9 @@ def search_answer(number):
else:
session.attributes["lastCall"] = "search_answer"
return question("Wonach wollen Sie suchen?")
if obj is None: # should never be called
return question("Error. Wonach wollen Sie suchen?")
links = util.get_session_value(session.attributes, "lastSearch")
# if the site uses relative links, make absolute ones
@ -122,9 +117,12 @@ def search_answer(number):
else:
newLinks.append( link)
links = newLinks
if int(number) > len(links):
return question("Dieser Artikel existiert leider nicht, versuchen Sie eine andere Nummer.")
art = obj.read_headlines(links[int(number)-1])
response = ""
for element in art:
response += element
@ -132,7 +130,7 @@ def search_answer(number):
session.attributes["lastCall"] = "search2"
return question(response)
# https://github.com/markuskiller/textblob-de
@ask.intent('Senti', mapping={'number': 'Nummer'}, default={'number': 1})
def get_sentiment(number):
site = util.get_session_value(session.attributes, "siteName")
@ -172,11 +170,16 @@ def get_sentiment(number):
sent = newText.sentiment[0]
if sent < 0:
good = "shit"
good = "eher negativ"
else:
good = "nice"
good = "positiv"
return question(good)
return question("Das Sentiment ist " + good)
### ###
# DEFUALT #
### ###
@ask.intent('AMAZON.HelpIntent')
def help():
@ -195,6 +198,10 @@ def launch():
def session_ended():
return "{}", 200
### ###
# INIT #
### ###
if __name__ == '__main__':
if 'ASK_VERIFY_REQUESTS' in os.environ:
@ -202,4 +209,4 @@ if __name__ == '__main__':
if verify == 'false':
application.config['ASK_VERIFY_REQUESTS'] = False
application.run(host='127.0.0.1',port=80)
application.run(host='0.0.0.0',port=80)

View File

@ -1,36 +0,0 @@
# http://www.ulliwaltinger.de/sentiment/
# https://github.com/solariz/german_stopwords
#!/usr/bin/env python
# https://github.com/markuskiller/textblob-de
# -*- coding: utf-8 -*-
import nltk
import copy
import encodings
import csv
from siteobj import *
from nltk.corpus import treebank
from textblob_de import TextBlobDE as TextBlob
def get_sentiment(url):
NewsText = obj.read_article(url)
newText = ""
for text in NewsText:
newText += text
newText = TextBlob(newText)
sent = newText.sentiment[0]
if sent < 0:
good = "shit"
else:
good = "nice"
print(good, newText.sentiment,"\n", link.split("/")[-1], "\n")
return good
obj = Golem()
news, links = obj.get_news()
for link in links:
get_sentiment(link)

View File

@ -1,20 +1,20 @@
def check_session_for(sessionAttributes, key):
"""Returns True or False based on wether the variable exists"""
if key in sessionAttributes:
return True
else:
return False
# returns value to key in session if set
# returns None if not
def session_value_is(sessionAttributes, key, value):
"""Returns True or False based on wether the variable has the expected Value"""
if key in sessionAttributes and sessionAttributes[key] == value:
return True
else:
return False
def get_session_value(sessionAttributes, key):
"""Returns the Value or None"""
if key in sessionAttributes:
return sessionAttributes[key]
else: