import os, logging
from flask import Flask, request, render_template, jsonify
from flask_restplus import Api
from flask_ask import Ask, statement
import requests

from public import input

app = Flask(__name__)

ROOT_URL = os.getenv('ROOT_URL', 'localhost')
VERSION_NO = os.getenv('VERSION_NO', '1.0')
APP_NAME = os.getenv('APP_NAME', "Devil's Advocate")
DEBUG = os.getenv('DEBUG', False)
SENTIMENT_URL = os.getenv("SENTIMENT_URL", "https://ns3-sentiment.herokuapp.com/")
SENTIMENT_ENDPOINT = os.getenv("SENTIMENT_ENDPOINT", 'parse')
ACQUIRE_URL = os.getenv("SENTIMENT_URL", "https://ns3-acquire.herokuapp.com/")
ACQUIRE_ENDPOINT = os.getenv("ACQUIRE_ENDPOINT", 'find')
print APP_NAME, VERSION_NO
# api = Api(app, version=VERSION_NO, title=APP_NAME)

ask = Ask(app, '/alexa')
logging.getLogger('flask_ask').setLevel(logging.DEBUG)


# public_ns = api.namespace('Public', description='Public methods')

# if DEBUG:
#     private_ns = api.namespace('Private', description='Private methods (visible in debug only)')
#     private_ns.add_resource(input.InputDebugText, '/input/debug')
    
# public_ns.add_resource(input.Input, '/input')

@ask.intent('Hello')
def startup():
    text = render_template('start')
    return statement(text)

def create_coherent_list(claim_arr):
    to_say = ', '.join(claim_arr[:-1])
    to_say += 'and ' + claim_arr[-1]
    return to_say

@ask.intent("GetNews")
def get_news(topic):
    params = {
        'topic' : topic
    }
    # articles = requests.get(ACQUIRE_URL + ACQUIRE_ENDPOINT, params=params)
    # response = articles.json()
    response = [0]
    to_say = []
    for article in response:
        claim_params = {
            'article': "Donald J. Trump is president-elect of the United States."
        }
        claim = requests.post(SENTIMENT_URL + SENTIMENT_ENDPOINT, params=claim_params)
        to_say.append(claim.json()['claim'])
    sentence = create_coherent_list(to_say)
    return statement(render_template('news', topic=topic, opinion=sentence))

if __name__ == '__main__':
    app.run()
    
@@ -519,16 +519,23 @@
 OINT%22, '
+api/v1/
 parse')%0A
@@ -663,16 +663,23 @@
 OINT%22, '
+api/v1/
 find')%0Ap
@@ -1820,23 +1820,32 @@
 DPOINT, 
-params=
+data=json.dumps(
 claim_pa
@@ -1845,24 +1845,25 @@
 laim_params)
+)
 %0A        to_

fix json not going through