-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIGAPI.py
More file actions
81 lines (66 loc) · 2.45 KB
/
IGAPI.py
File metadata and controls
81 lines (66 loc) · 2.45 KB
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
from InstagramAPI import InstagramAPI
import pandas as pd
from time import sleep
import json
profile = {}
class igAPI:
def __init__(self):
self.api = InstagramAPI("mexicansombreroless", "mannheimzittau")
def getLikesList(self):
hasMorePosts = True
maxId=""
api=self.api
api.login()
i = 0
api.getSelfUsernameInfo()
result = api.LastJson
media_acount = result['user']['media_count'] #Get user posts
print(media_acount)
listofLists = [[] for i in range(media_acount+1)]
##username_id = result['user']['pk'] # Get user ID
while hasMorePosts:
api.getSelfUserFeed(maxid=maxId)
if api.LastJson['more_available'] is not True:
hasMorePosts = False #stop condition
print ("stopped")
result1 = api.LastJson
maxId = api.LastJson.get('next_max_id','')
if 'items' in result1.keys():
for item in result1['items']:
mediaId = item['id']
api.getMediaLikers(mediaId) # Get users who liked
users = api.LastJson['users']
i+=1
for user in users: # Push users to list
listofLists[i].append(user['username'])
self.append(listofLists[i],i,profile)
sleep(3)
self.writeInfo('PhotosFeed','a',profile)
def appendList(self):
return []
def append (self, data, key, dictAppend):
"""
Append Data to Dictionary
->data: data inside key (can be a dictionary)
->key: key for the data to be saved
->dictAppend: in which dictionary will the data be saved
"""
if (key in dictAppend):
dictAppend[key].update(data)
else:
dictAppend.update({key : data})
return dictAppend
def writeInfo(self, jsonPath, action, dictionary):
"""
Write info to JSON FILE
->jsonPath: json file name
->action: w for overwirte a for append
"""
jsonPath = jsonPath + ".json"
with open (jsonPath, action, encoding='utf8') as file:
json.dump(dictionary, file, sort_keys=True, ensure_ascii=False, indent=4, separators=(',',':'))
def main ():
Ins = igAPI()
Ins.getLikesList()
if __name__ == "__main__":
main()