-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
60 lines (48 loc) · 1.51 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
import json
import time
from instagram_private_api import Client, ClientCompatPatch
# Bootstrap code
cookies = None
try:
with open("cookies.pkl", "rb") as read_cookies:
cookies = read_cookies.read()
except:
pass
user_name = ""
password = ""
if cookies is None:
print("not using cookies")
api = Client(user_name, password, auto_patch=True)
else:
print("using cookies")
api = Client(user_name, password, cookie=cookies, auto_patch=True)
cookies = api.cookie_jar.dump()
with open("cookies.pkl", "wb") as save_cookies:
save_cookies.write(cookies)
photo_urls = []
def parse_results(results):
for result in results["items"]:
try:
carousel_imgs = result["media"]["carousel_media"]
# print("have carousel media")
for img in carousel_imgs:
photo_urls.append(img["images"]["standard_resolution"]["url"])
except KeyError as e:
# print("dont have it")
photo_urls.append(result["media"]["images"]["standard_resolution"]["url"])
results = api.saved_feed()
# print(json.dumps(results["items"]))
parse_results(results)
next_max_id = results.get('next_max_id')
print("sleeping for 1.5 seconds, next max id is: " + str(next_max_id))
time.sleep(1.5)
while next_max_id:
results = api.saved_feed(max_id=next_max_id)
parse_results(results)
next_max_id = results.get('next_max_id')
with open("urls.txt", "a") as myfile:
for url in photo_urls:
myfile.write(url + "\n")
photo_urls = []
print("sleeping for 1.5 seconds, next max id is: " + str(next_max_id))
time.sleep(1.5)