-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
70 lines (63 loc) · 2.53 KB
/
app.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask import Flask, request
from flask import jsonify
from instasentiments import getPublicProfileCaptions, getPrivateProfileCaptions, getSentiments
#Initializing our application
app = Flask(__name__)
#Route that sends the JSON response to the client
@app.route('/requestjson', methods=['POST','GET'])
def receiveSendJSON():
if request.method == 'GET': #We want some data to be received by the server, hence we return an error if the method was GET
return "<h1 style='color:red'> GET requests are not allowed, send some JSON data to this URL. </h1>"
else:
data = request.json # JSON received from the client
if data['type'] == 'Public':
login_id = data['login_id']
print(login_id)
result, profile_pic, full_name = getPublicProfileCaptions(login_id)
print(full_name)
if type(result) == str:
return jsonify({
'Type':'Fail',
'Value': result
})
else:
sentiments = getSentiments(result)
if type(sentiments) == str:
return jsonify({
'Type': 'Fail',
'Value': sentiments,
})
else:
return jsonify({
'Type': 'Success',
'Value': sentiments,
'Picture': profile_pic,
'Name': full_name
})
elif data['type'] == 'Private':
login_id = data['login_id']
login_username = data['login_username']
password = data['password']
print(login_id)
result, profile_pic, full_name = getPrivateProfileCaptions(login_id, login_username, password)
if type(result) == str:
return jsonify({
'Type': 'Fail',
'Value': result
})
else:
sentiments = getSentiments(result)
if type(sentiments) == str:
return jsonify({
'Type': 'Fail',
'Value': sentiments
})
else:
return jsonify({
'Type': 'Success',
'Value': sentiments,
'Picture': profile_pic,
'Name': full_name
})
if __name__ == '__main__':
app.run(debug=False,threaded=False)