-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
183 lines (160 loc) · 4.93 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
from flask import Flask
from flask import request
from reddit_search import *
from channel_stats import *
from video_stats import *
from youtube_search import *
from tumblr import *
# from insta import *
from twitter import *
from sentiment import *
from Aggregate import *
from ner import *
from time_dependent_aggregate import *
from ner_aggregate import *
from bson.objectid import ObjectId
import pymongo
from pymongo import MongoClient
from datetime import datetime
app = Flask(__name__)
@app.route('/')
def baseurl():
print(datetime.today())
return("working")
@app.route('/reddit/search/',methods=['GET'])
def redditapi():
Sort = request.args.get('sort')
Limit = request.args.get('limit')
Search = request.args.get('q')
if Limit is None:
Limit=1000
if (Sort=="Top"):
return reddittop(Search,number=int(Limit))
elif (Sort=='Hot'):
return reddithot(Search,number=int(Limit))
else:
return redditnew(Search,number=int(Limit))
@app.route('/youtube/stats/',methods=['GET'])
def youtubestats():
channelId = request.args.get('channelId')
videoId = request.args.get('videoId')
if channelId is not None:
return Channel_stats(channelId)
elif videoId is not None:
return Video_stats(videoId)
else:
return ("Provide channel Id or video Id")
@app.route('/youtube/search/',methods=['GET'])
def youtube_search():
Search = request.args.get('q')
Limit = request.args.get('limit')
if (Limit is None) or (int(Limit)>50):
return Video_Search(Search)
else:
return Video_Search(Search,max_results=int(Limit))
@app.route('/tumblr/search/',methods=['GET'])
def tumblr():
Search = request.args.get('q')
return tumblrsearch(Search)
@app.route('/sentiment/',methods=['GET'])
def sentiment_():
Search = request.args.get('q')
return sentiment_analysis(Search)
#
# @app.route('/insta/search/top/',methods=['GET'])
# def Insta_top():
# Search = request.args.get('q')
# Limit = request.args.get('limit')
# if (Limit is None):
# return insta_top(Search)
# else:
# return insta_top(Search,amount=int(Limit))
#
# @app.route('/insta/search/recent/',methods=['GET'])
# def Insta_recent():
# Search = request.args.get('q')
# Limit = request.args.get('limit')
# if (Limit is None):
# return insta_recent(Search)
# else:
# return insta_recent(Search,amount=int(Limit))
@app.route('/twitter/search/',methods=['GET'])
def Twitter():
Search = request.args.get('q')
Limit = request.args.get('limit')
if (Limit is None) or (int(Limit)>3000):
return twitter_past(Search)
else:
return twitter_past(Search,count=int(Limit))
@app.route('/twitter/stream/',methods=['GET'])
def Twitter_():
Search = request.args.get('q')
Time_Limit = request.args.get('time')
if Time_Limit == None:
return twitter_stream(Search)
return twitter_stream(q=Search,t=float(Time_Limit)*60)
@app.route('/search/',methods=['GET'])
def All_data():
Search = request.args.get('q')
print("Searching started")
tumblrsearch(Search)
Video_Search(Search)
reddithot(Search)
twitter_past(Search)
twitter_stream(q=Search)
return True
@app.route('/ner/',methods=['GET'])
def namedER():
sentence = request.args.get('q')
return tags(sentence)
@app.route('/mentions/',methods=['GET'])
def mention():
Search = request.args.get('q')
return mentions(Search)
@app.route('/ner_mentions/',methods=['GET'])
def ner_mention():
Search = request.args.get('q')
return ner_mentions(Search)
@app.route('/aggregate/',methods=['GET'])
def aggregate():
Search = request.args.get('q')
return insert_data(Search)
@app.route('/aggregate_data/',methods=['GET'])
def aggregate_data():
Search = request.args.get('q')
return get_data_aggregate(Search)
@app.route('/aggregate_ner_data/',methods=['GET'])
def aggregate_ner_data():
Search = request.args.get('q')
return get_data_ner_aggregate(Search)
@app.route('/deletion/',methods=['GET'])
def deletion():
id_ = request.args.get('id')
x = db["aggregate"].find({"profiles":str(id_)},{"_id","profiles"})
x_ner = db["aggregate"].find({"profiles":str(id_)},{"_id","profiles"})
try:
profiles = x[0]["profiles"]
profiles.remove(str(id_))
output1 = {"profiles":profiles,"updatedAt": datetime.now()}
db["aggregate"].update_one({"_id":x[0]["_id"]},{"$set":output1})
db["ner_aggregate"].update_one({"_id":x_ner[0]["_id"]},{"$set":output1})
except:
return "Done"
return "done"
@app.route('/insertion/',methods=['GET'])
def insertion():
id_ = request.args.get('id')
x = db["profile"].find({"_id":ObjectId(id_)},{"brand"})
try:
data = db["aggregate"].find({"tag":x[0]["brand"]},{"_id","profiles"})
ner = db["ner_aggregate"].find({"tag":x[0]["brand"]},{"_id","profiles"})
profiles = data[0]["profiles"]
profiles.append(str(x[0]["_id"]))
output1 = {"profiles":profiles,"updatedAt": datetime.now()}
db["aggregate"].update_one({"_id":data[0]["_id"]},{"$set":output1})
db["ner_aggregate"].update_one({"_id":ner[0]["_id"]},{"$set":output1})
except:
return "Done"
return "done"
if __name__ == '__main__':
app.run(debug=False,host='0.0.0.0')