import sys
# sys.path.append("/home/yswg/amazon_selection/")
# from comment_analytics.comment_analytics import CommentAnalytics
from app.comment_analytics.comment_analytics import CommentAnalytics
from flask import Flask, request, jsonify, Blueprint
from flask_cors import cross_origin  # 跨域请求
handle_obj = CommentAnalytics()

# app = Flask(__name__)
# print("app:", app)
comment_api_bp = Blueprint('comment_api', __name__)


@comment_api_bp.route('/analyze_comments', methods=['POST'])
@cross_origin()
def analyze_comments():
    data = request.get_json()
    print("data:", data)
    site_name = data['site_name']
    asin = data['asin']
    phrases_counts = int(data['phrases_counts'])
    if request.method == 'POST':
        print("data:", site_name, asin, phrases_counts)
        # handle_obj = CommentAnalytics(site_name=site_name, asin=asin, phrases_counts=phrases_counts)
        handle_obj.run(site_name=site_name, asin=asin, phrases_counts=phrases_counts)
        return jsonify({"status_code": 200, "message": "success"})
    else:
        return jsonify({"status_code": 500, "message": "failed"})


# if __name__ == '__main__':
#     app.run('0.0.0.0', 5000, debug=True)
