forked from pmcamp/lucky
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path19wu2lucky.py
41 lines (39 loc) · 1.6 KB
/
19wu2lucky.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
# coding: utf-8
import csv
def mklucky(csvfile):
lucky_data = []
spamReader = csv.reader(open(csvfile, 'rb'))
for i in spamReader:
if spamReader.line_num == 1:
continue
else:
email = i[3]
at = email.find("@")
if at != -1:
if at <= 4:
hidden = email[0] + "***" + email[at-1:at] + email[at:]
else:
hidden = email[0:2] + "***" + email[at-3:at] + email[at:]
else:
length = len(email)
hidden = email[0:4] + "***" + email[length-4:length]
lucky_str = "%s,%s,%s" % (i[2], hidden, i[3])
lucky_data.append(lucky_str)
f = open("./js/luckydata.js","w")
db = "var data = ['%s']" % "','".join(lucky_data)
f.write(db)
f.close()
if __name__ == "__main__":
import sys
if len(sys.argv) <= 1:
print " *********************************************"
print " * 19wu2lucky.py *"
print " * *"
print " * -- PyCon China 2014 lucky data maker *"
print " * *"
print " * Usage: python 19wu2lucky.py 19wu_data.csv *"
print " * *"
print " * By: [email protected] *"
print " *********************************************"
else:
mklucky(sys.argv[1])