-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
165 lines (122 loc) · 3.74 KB
/
main.py
File metadata and controls
165 lines (122 loc) · 3.74 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import requests, threading,time
import datetime
import argparse,os
import matplotlib.pyplot as plt
hed = {
'Host':'www.instagram.com',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0'}
SLEEPREFRESH = 0.8 # 5 = 5 detik
def hitung(jumlah): #mengubah angka contoh : 3200000 menjadi 3.200.000
jumlah = str(jumlah)
dt = []
pjg = len(jumlah)
p = jumlah
if pjg > 3:
sisa = pjg % 3
jml = pjg //3
if sisa != 0:
dt.append(p[:sisa])
p = p[sisa:]
for i in range(jml):
dt.append(p[:3])
p = p[3:]
jumlah = '.'.join(dt)
return jumlah
def jam():
f = datetime.datetime.now().strftime("%H:%M:%S")
return f
class Mulai:
def __init__(self, username, update=1, showbar=6, output=False):
self.user = username
self.update = 60*update #600 = 10menit
self.showbar = showbar
self.trakhir = 0
self.menit_awal = 0
self.output = output
self.data = [[[0]*showbar], [['--']*showbar]]
def st(self):
start_sec = 0
while True:
if start_sec == 0:
start_sec = time.time()
try:
js = requests.post(f'http://www.instagram.com/{self.user}/channel/?__a=1', headers=hed).json()
jml = js['graphql']['user']['edge_followed_by']['count']
if self.trakhir == 0:
self.menit_awal = jml
self.trakhir = jml
if jml < self.trakhir:
y = ('-'+str(self.trakhir-jml))
else:
y = ('+'+str(jml-self.trakhir))
self.laporan = f'{jam()} | {hitung(str(jml))} ({y})'
print(self.laporan)
self.trakhir = jml
except:
pass
if time.time()-start_sec >= self.update:
jum = jml-self.menit_awal
self.data[0][0].append(jum)
self.data[1][0].append(jam())
start_sec = time.time()
t = threading.Thread(target=self.chart)
t.start()
self.menit_awal = jml
time.sleep(SLEEPREFRESH)
def chart(self):
def autolabel(rects):
for rect in rects:
height = rect.get_height()
if height > 0 :
h = '+'+str(height)
else:
h = height
plt.annotate('{}'.format(h),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 2), # 3 points vertical offset
textcoords="offset points",
ha='center', va='bottom')
p = plt.bar(self.data[1][0][-self.showbar:], self.data[0][0][-self.showbar:], color='#17eaea')
autolabel(p)
plt.xticks(rotation = 20)
plt.savefig(self.user+'.jpg')
if output != False:
if output == None:
n = self.user+'.txt'
else:
n = output
if self.data[0][0][-1] > 0 :
perubahan = '+'+str(self.data[0][0][-1])
else:
perubahan = self.data[0][0][-1]
if os.path.exists(n):
with open(n, 'a') as tls:
tls.write(f'{jam()} | {hitung(self.menit_awal)} ({perubahan})\n')
else:
with open(n, 'w') as tls:
tls.write(f'{jam()} | {hitung(self.menit_awal)} ({perubahan})\n')
plt.close('all')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--update", help="how many minutes to update char bar. default: 1 minute",type=int)
parser.add_argument("-s", "--showbar", help="how many bar in chart. default: 6 bar", type=int)
parser.add_argument("-o", "--output", help="save history in a file", nargs='?', const=True) #if isi option -o kosong maka nilai nya adalah True(const=True), tapi tidak berlaku jika -o tidak dipanggil
args = parser.parse_args()
update = 1
showbar = 6
output = False
if args.update:
if args.update > 0:
update = args.update
if args.showbar:
if args.showbar > 0:
showbar = args.showbar
if args.output:
if type(args.output) is not bool:
output = str(args.output)
else:
output = None
name = str(input('Username : @'))
p = Mulai(name, update, showbar, output)
p = p.st()