-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
286 lines (231 loc) · 6.93 KB
/
main.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
from os import error
from instagrapi import Client
from flask import Flask,jsonify
import json
import random
print('Login in..')
def write_file(data, filename):
fh = open(filename, "w")
try:
fh.write(json.dumps(data))
finally:
fh.close()
def read_file(filename):
fh = open(filename, "r")
return json.load(fh)
ACCOUNT_USERNAME = 'maidenvaper'
ACCOUNT_PASSWORD = 'Hyderabad123'
IG_CREDENTIAL = ACCOUNT_USERNAME
# # IG_CREDENTIAL = random.choice(ACCOUNT_USERNAMES)
print(IG_CREDENTIAL)
cl = None
try:
cl = Client(read_file(IG_CREDENTIAL))
print("valid credentials.json")
except:
print("invalid credentials.json")
cl = Client()
print('done')
cl.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)
print("valid login")
write_file(cl.get_settings(), IG_CREDENTIAL)
app = Flask(__name__)
@app.route("/")
def index():
try:
return "Hello World!"
except:
return 'Please Connect to internet'
@app.route("/favicon.ico")
def index2():
try:
print('faviconn')
return "favicon.ico"
except:
return 'Please Connect to internet'
@app.route("/user/<username>")
def user(username):
user_id = cl.user_id_from_username(username)
medias = cl.user_info(user_id).dict()
print(type(medias))
return medias
@app.route('/followers/<username>')
def followers(username):
user_id = cl.user_id_from_username(username)
medias = cl.user_followers(user_id)
medias=str(medias)
list=medias.replace("), 'media_type'","', 'media_type'")
list=list.replace('HttpUrl(','')
list=list.replace("='",":'")
list=list.replace(",'username'","','username'")
list=list.replace("UserShort(pk","UserShort{pk")
list=list.replace("pk=","pk:")
list=list.replace(",username","',username")
list=list.replace("stories=[])","stories=[]}")
list=list.replace("UserShort","")
list=list.replace(")","")
list=list.replace(", stories=[]","")
list=list.replace("full_name=","full_name:")
list=list.replace("'",'"')
list=list.replace(",",', "')
list=list.replace(":",'" :')
list=list.replace('"https" :','"https:')
list=list.replace('{','{"')
list=list.replace('_ ','_')
print(list)
data=json.loads(list)
temp = []
for t in data:
data[t].pop(" full_name",None)
data[t].pop(' scheme',None)
data[t].pop(' host',None)
data[t].pop(' tld',None)
data[t].pop(' host_type',None)
data[t].pop(' path',None)
data[t].pop(' query',None)
print(data[t])
print(type(data[t]))
print(type(data[t]))
temp.append(data[t])
return jsonify(temp)
@app.route('/following/<username>')
def following(username):
user_id = cl.user_id_from_username(username)
medias = cl.user_following(user_id)
medias=str(medias)
list=medias.replace("), 'media_type'","', 'media_type'")
list=list.replace('HttpUrl(','')
list=list.replace("='",":'")
list=list.replace(",'username'","','username'")
list=list.replace("UserShort(pk","UserShort{pk")
list=list.replace("pk=","pk:")
list=list.replace(",username","',username")
list=list.replace("stories=[])","stories=[]}")
list=list.replace("UserShort","")
list=list.replace(")","")
list=list.replace(", stories=[]","")
list=list.replace("full_name=","full_name:")
list=list.replace("{","{'")
list=list.replace(":","':")
list=list.replace('" ','" ')
json.dumps(list)
return list
@app.route("/hastag/top/<hastag>")
def hastag_top(hastag):
medias = cl.hashtag_medias_top(str(hastag),50)
hastag=[]
for aap in medias:
data=aap.dict()
data.pop("caption_text",None)
print(data)
hastag.append(data)
list=str(hastag)
list=list.replace("), 'media_type'","', 'media_type'")
list=list.replace('HttpUrl(','')
json.dumps(hastag)
return hastag
@app.route("/hastag/recent/<hastag>")
def hastag_recent(hastag):
medias = cl.hashtag_medias_recent(str(hastag),50)
hastag=[]
for aap in medias:
data=aap.json()
print(data)
hastag.append(data)
hastag=str(hastag)
json.dumps(hastag)
return hastag
@app.route("/stories/<username>")
def user_stories(username):
user_id = cl.user_id_from_username(username)
data= cl.user_stories(user_id)
story=[]
for media in data:
media=media.json()
story.append(media)
list=str(story)
list=list.replace("'","")
list=list.replace("']","]")
json.dumps(list)
return list
@app.route("/posts/<username>")
def user_posts(username):
user_id = cl.user_id_from_username(username)
medias = cl.user_medias(user_id)
list=[]
for medis in medias:
# print(type(medias))
# print(type(medis))
data=medis.json()
# print(type(data))
dictiy=json.loads(data)
# print(type(dictiy))
dictiy.pop("caption_text", None)
data=json.dumps(dictiy)
list.append(data)
list=str(list)
list=list.replace("'","")
list=list.replace("']","]")
json.dumps(list)
return list
@app.route("/media-comments/<media_id>")
def media_comment(media_id):
medias = cl.media_comments(str(media_id))
list=[]
for i in medias:
comments=i.json()
print(comments)
list.append(comments)
list=str(list)
list=list.replace("'","")
list=list.replace("']","]")
json.dumps(list)
return list
@app.route("/media-likes/<media_id>")
def media_like(media_id):
medias = cl.media_likers(str(media_id))
list=[]
for i in medias:
comments=i.json()
print(comments)
list.append(comments)
list=str(list)
list=list.replace("\\", '')
list=list.replace("'","")
list=list.replace("']","]")
json.dumps(list)
return list
@app.route('/me-not-following-back/<username>')
def me_not_following_back(username):
user_id = cl.user_id_from_username(username)
followers=cl.user_followers(user_id)
following=cl.user_following(user_id)
data=[]
for items in followers:
if items not in following:
users=cl.user_info(items).json()
data.append(users)
print(users)
data=str(data)
list=data.replace("'","")
# list=list.replace("']","]")
json.dumps(list)
return list
@app.route('/they-not-following-back/<username>')
def they_not_following_back(username):
user_id = cl.user_id_from_username(username)
followers=cl.user_followers(user_id)
following=cl.user_following(user_id)
data=[]
for items in following:
if items not in followers:
users=cl.user_info(items)
data.append(users)
print(users)
data=str(data)
list=data.replace("'","")
list=list.replace("']","]")
json.dumps(data)
return data
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8080)