-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_server.py
More file actions
32 lines (28 loc) · 1.14 KB
/
api_server.py
File metadata and controls
32 lines (28 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from flask import Flask, Response, jsonify
from flask_restplus import Api, Resource, fields, reqparse
from flask_cors import CORS, cross_origin
import os
from sentimentanalysis import scrape_tweet as sc
app = Flask(__name__)
app.config["DEBUG"] = True
CORS(app)
api = Api(app, version='1.0', title='API for sentiment analysis', validate=False)
ns = api.namespace('api_server', 'Returns sentiments on string on twitter')
model_input = api.model('Enter the company or celebrity here', {"Sentiment": fields.String(), "Number": fields.String()})
#port = int(os.getenv('PORT', 8080))
@ns.route('/sentiment')
class Sentiment(Resource):
@api.response(200, "Success", model_input)
@api.expect(model_input)
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('Sentiment', type=str)
parser.add_argument('Number', type =str)
args = parser.parse_args()
inp = str(args["Sentiment"])
inp2 = str(args["Number"])
result = sc(inp, inp2)
return result
if __name__=="__main__":
app.run(host=os.getenv('IP', '0.0.0.0'),
port=int(os.getenv('PORT', 4444)))