This repository has been archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
query.py
53 lines (48 loc) Β· 1.69 KB
/
query.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
import json
import time
import urllib.request
def start(instagramID):
max_id=''
IGcontent=''
cc_count=0
url_host='https://www.instagram.com/'
url_path = str(instagramID)+'/?__a=1&max_id='
try:
check = urllib.request.urlopen(url_host+url_path+max_id)
except Exception as Q:
try:
if(int(Q.getcode()/100)==4):
print('User not found')
except:
print('Please check your network status')
exit()
while 1:
try:
url = url_host+url_path+max_id
request = urllib.request.Request(url=url)
response = urllib.request.urlopen(request,timeout=5)
res_body = response.read()
j=json.loads(res_body.decode("utf-8"))
if j['user']['is_private'] != True:
items=j['user']['media']['nodes']
for i in items:
if 'caption' in i:
IGcontent+=str(i['caption'])
else:
print('This user is private! Sorry!')
exit()
max_id = items[len(items)-1]['id']
if j['user']['media']['page_info']['has_next_page']==True:
cc_count+=len(items)
stdout = '('
stdout += str(int(cc_count/j['user']['media']['count']*100))
stdout +='%)'
stdout += ' Now query '+str(cc_count)+' posts '
print(stdout)
else:
print('100%! Wait for rendering')
return IGcontent
except Exception as Q:
print(Q)
print('Time out? Wait 10 seconds (Use Ctrl-c to KeyboardInterrupt)')
time.sleep(10)