-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
Copy pathinsta_api.py
162 lines (143 loc) · 5.4 KB
/
insta_api.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
from concurrent.futures import ThreadPoolExecutor
import tornado.ioloop
import tornado.web
from tornado.concurrent import run_on_executor
from tornado.gen import coroutine
# import file
try:
from instagram_monitering.insta_datafetcher import *
from instagram_monitering.subpinsta import *
except:
from insta_datafetcher import *
from subpinsta import *
MAX_WORKERS = 10
class StartHandlerinsta(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(max_workers=MAX_WORKERS)
@run_on_executor
def background_task(self, user, tags, type, productId):
try:
instasubprocess(user=user, tags=tags, type=type, productId=productId)
except:
print("error::background_task>>", sys.exc_info()[1])
@coroutine
def get(self):
try:
q = self.get_argument("q")
user = self.get_argument("userId")
type = self.get_argument("type")
productId = self.get_argument("productId")
except:
self.send_error(400)
if " " in q:
q = q.replace(" ", "")
self.background_task(user=user, tags=q, type=type, productId=productId)
temp = {}
temp["query"] = q
temp["userId"] = user
temp["status"] = True
temp["productId"] = productId
print(
"{0}, {1}, {2}, {3}".format(
temp["userId"], temp["productId"], temp["query"], temp["status"]
)
)
self.write(ujson.dumps(temp))
class StopHandlerinsta(tornado.web.RequestHandler):
def get(self):
try:
q = self.get_argument("q")
user = self.get_argument("userId")
# tags = self.get_argument("hashtags")
productId = self.get_argument("productId")
except:
self.send_error(400)
obj = InstaPorcessClass()
result = obj.deletProcess(tags=q, user=user, productId=productId)
temp = {}
temp["query"] = q
temp["userId"] = user
temp["productId"] = productId
temp["status"] = result
print(
"{0}, {1}, {2}, {3}".format(
temp["userId"], temp["productId"], temp["query"], temp["status"]
)
)
self.write(ujson.dumps(temp))
class StatusHandlerinsta(tornado.web.RequestHandler):
def get(self):
try:
q = self.get_argument("q")
user = self.get_argument("userId")
productId = self.get_argument("productId")
# tags = self.get_argument("hashtags")
except:
self.send_error(400)
obj = InstaPorcessClass()
result = obj.statusCheck(tags=q, user=user, productId=productId)
temp = {}
temp["query"] = q
temp["userId"] = user
temp["status"] = result
temp["productId"] = productId
print(
"{0}, {1}, {2}, {3}".format(
temp["userId"], temp["productId"], temp["query"], temp["status"]
)
)
self.write(ujson.dumps(temp))
# class SenderHandlerinsta(tornado.web.RequestHandler):
# def get(self):
# try:
# q = self.get_argument("q")
# user = self.get_argument("userId")
# type = self.get_argument("type")
# productId = self.get_argument("productId")
# except:
# self.send_error(400)
# recordsobj = DBDataFetcher(user=user, tags=q, type=type, productId=productId)
# data = recordsobj.dbFetcher()
# self.write(data)
class SenderHandlerinstaLess(tornado.web.RequestHandler):
def get(self):
try:
q = self.get_argument("q")
user = self.get_argument("userId")
type = self.get_argument("type")
productId = self.get_argument("productId")
date = self.get_argument("date")
limit = self.get_argument("limit")
except:
self.send_error(400)
recordsobj = DBDataFetcher(user=user, tags=q, type=type, productId=productId)
data = recordsobj.DBFetcherLess(limit=limit, date=date)
# print("{0}, {1}, {2}, {3}".format(temp["userId"], temp["productId"], temp["query"], temp["status"]))
self.write(data)
class SenderHandlerinstaGreater(tornado.web.RequestHandler):
def get(self):
try:
q = self.get_argument("q")
user = self.get_argument("userId")
type = self.get_argument("type")
productId = self.get_argument("productId")
date = self.get_argument("date")
limit = self.get_argument("limit")
except:
self.send_error(400)
recordsobj = DBDataFetcher(user=user, tags=q, type=type, productId=productId)
data = recordsobj.DBFetcherGreater(limit=limit, date=date)
# print("{0}, {1}, {2}, {3}".format(temp["userId"], temp["productId"], temp["query"], temp["status"]))
self.write(data)
if __name__ == "__main__":
application = tornado.web.Application(
[
(r"/instagram/monitoring/start", StartHandlerinsta),
(r"/instagram/monitoring/stop", StopHandlerinsta),
(r"/instagram/monitoring/status", StatusHandlerinsta),
(r"/instagram/monitoring/less", SenderHandlerinstaLess),
(r"/instagram/monitoring/greater", SenderHandlerinstaGreater),
]
)
application.listen(7074)
print("server running")
tornado.ioloop.IOLoop.instance().start()