-
Notifications
You must be signed in to change notification settings - Fork 19
/
main-lite.py
104 lines (84 loc) · 2.47 KB
/
main-lite.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from insta import Instagram
import os
import json
import pystache
import io
import webbrowser
numer = sys.argv[1]
#modify here
insta = Instagram('usernmefoo', 'passwordfoo')
if insta.login() == False:
print "Login failed"
sys.exit(2)
temp = insta.getTotalUserFeed(numer)
followers = insta.getTotalFollowers(numer)
followings = insta.getTotalFollowings(numer)
followersnum=len(followers)
followingsnum=len(followings)
notfollowedback = []
for fr in followings:
flag = True
for fg in followers:
if fg["pk"] == fr["pk"]:
flag = False
break
if flag:
notfollowedback.append(fr)
newfollowers = []
if os.path.exists('followers.json'):
with open('followers.json') as data_file:
oldfollowers = json.load(data_file)
for fr in followers:
flag = True
for fg in oldfollowers:
if fg["pk"] == fr["pk"]:
flag = False
break
if flag:
newfollowers.append(fr)
newunfollowers = []
if os.path.exists('followers.json'):
with open('followers.json') as data_file:
oldfollowers = json.load(data_file)
for fr in oldfollowers:
flag = True
for fg in followers:
if fg["pk"] == fr["pk"]:
flag = False
break
if flag:
newunfollowers.append(fr)
newfollowings = []
if os.path.exists('followings.json'):
with open('followings.json') as data_file:
oldfollowings = json.load(data_file)
for fr in followings:
flag = True
for fg in oldfollowings:
if fg["pk"] == fr["pk"]:
flag = False
break
if flag:
newfollowings.append(fr)
with open('followers.json', 'w') as outfile:
json.dump(followers, outfile)
with open('followings.json', 'w') as outfile:
json.dump(followings, outfile)
file = open('template-lite.tpl', 'r')
html = file.readlines()
tpl = ''
for line in html:
tpl = tpl + " " + line
data = {
"username": [followersnum, followingsnum],
"notback": notfollowedback,
"newfollowers": newfollowers,
"newunfollowers":newunfollowers,
"newfollowings": newfollowings,
}
output = pystache.render(tpl, data)
with io.open('output.html', 'w', encoding='utf8') as f:
f.write(output)