-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstalytics.py
47 lines (40 loc) · 1.04 KB
/
instalytics.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
import csv
def scan(file):
while True:
field = next(file).split(",")
field = [f.strip() for f in field]
yield field
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
def instaTarray(filename):
file = open(filename,"r")
teesgenerator = scan(file)
teesfound = file_len(filename)
tarray = []
i=0
while(i<teesfound):
tee = next(teesgenerator)
tarray.append([tee[0],int(tee[-2])])
i+=1
return tarray
def sortTees(array,i):
tees = sorted(array, key=lambda score: score[i])
return tees
def topTees(filename):
LIKES = 1
tarray = instaTarray(filename)
print (len(tarray))
tarray = sortTees(tarray,LIKES)
for t in tarray:
print (t)
return tarray
def instalyticsCSV(tarray):
instadir = open("instanalytics.csv","w")
thoutput = csv.writer(instadir,delimiter = ',')
for t in tarray:
thoutput.writerow(t)
def instalyticA():
instalyticsCSV(topTees("instarank.csv"))