-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
66 lines (49 loc) · 1.89 KB
/
stats.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
from selenium import webdriver
import webbrowser
import json
import os
from modules.creds import getCreds
from modules.login import login
from modules.get_users import getUsers
if __name__ == '__main__':
credentials = getCreds()
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(options=options)
login(driver, credentials)
credentials['username'] = driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[5]/span/img').get_attribute('alt').split("'")[0]
driver.get('https://www.instagram.com/' + credentials['username'])
followers, varId = getUsers(driver, 'followers')
following, _ = getUsers(driver, 'following', varId)
infoDict = {}
for person in followers + following:
infoDict[person[0]] = person[1:]
followers = [f[0] for f in followers]
following = [f[0] for f in following]
youFollow = [a for a in following if a not in followers]
theyFollow = [a for a in followers if a not in following]
unfollowers = []
if os.path.exists('./files/oldFollowers.json'):
with open('./files/oldFollowers.json') as fp:
oldFollowers = json.load(fp)
unfollowers = [a for a in oldFollowers if a not in followers]
with open('./files/oldUnfollowers.json', 'w') as fp:
json.dump(unfollowers, fp)
with open('./files/oldFollowers.json', 'w') as fp:
json.dump(followers, fp)
if os.path.exists('./files/info.json'):
with open('./files/info.json') as fp:
oldDict = json.load(fp)
for person in unfollowers:
infoDict[person] = oldDict[person]
with open('./files/info.json', 'w') as fp:
json.dump(infoDict, fp)
def writeList(name:str):
with open('./files/' + name + '.js', 'w') as fp:
fp.write('var ' + name + ' = ')
json.dump(globals()[name], fp)
fp.write(';')
for listname in ('youFollow', 'theyFollow', 'unfollowers', 'infoDict'):
writeList(listname)
driver.quit()
webbrowser.open('stats.html')