-
Notifications
You must be signed in to change notification settings - Fork 21
/
py3_sm.py
executable file
·173 lines (146 loc) · 5.73 KB
/
py3_sm.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
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
166
167
168
169
170
171
172
173
#!/usr/bin/python3
# EmreOvunc
from pandas import ExcelFile
from argparse import ArgumentParser
from os import system, path
from hashlib import md5
from datetime import datetime as dt
parser = ArgumentParser()
parser.add_argument('--file', help='select a excel file')
data_parser = parser.add_argument_group('[Data Manipulation]')
data_parser.add_argument('--sheet-name', help='give a sheet name')
data_parser.add_argument('--column', help='give a column name')
args = parser.parse_args()
curr_time = dt.now().strftime("%H-%M-%S")
if path.isdir(args.sheet_name):
dirc = args.sheet_name + curr_time
else:
dirc = args.sheet_name
viewed = open('who_viewed.txt','r')
viewed_line = viewed.readlines()
clicked = open('who_clicked.txt','r')
clicked_line = clicked.readlines()
system('mkdir ' + dirc)
system('touch ' + dirc +'/user_md5s.txt')
usermd5s = open(dirc +"/user_md5s.txt","a")
system('touch ' + dirc +'/statistics.txt')
statistics = open(dirc +"/statistics.txt","a")
system('touch ' + dirc +'/user_clicked.txt')
userclicked = open(dirc +"/user_clicked.txt","a")
system('touch ' + dirc +'/user_viewed.txt')
userviewed = open(dirc +"/user_viewed.txt","a")
system('touch ' + dirc +'/mail_clicked.txt')
mailclick = open(dirc +"/mail_clicked.txt","a")
system('touch ' + dirc +'/mail_only_viewed.txt')
mailview = open(dirc +"/mail_only_viewed.txt","a")
system('touch ' + dirc +'/mail_no_action.txt')
mailnoaction = open(dirc +"/mail_no_action.txt","a")
clickedarr = []
viewedarr = []
fixedarr = []
mailviewed = []
mailclicked = []
total_clicked = 0
total_notclicked = 0
total_viewed = 0
total_user = 0
total_noaction = 0
total_error = 0
for lines in clicked_line:
md5sums = lines.strip().split(" ")[3]
if len(md5sums) == 32:
clickedarr.append(md5sums)
for lines in viewed_line:
md5sums = lines.strip().split(" ")[3]
if len(md5sums) == 32:
viewedarr.append(md5sums)
if args.file != '' or args.file != False:
excel = ExcelFile(args.file)
if args.sheet_name != "" and args.sheet_name != None:
sheet = excel.parse(args.sheet_name)
if args.column != "" and args.column != None:
for data in sheet[args.column]:
try:
md5s = md5(data.encode()).hexdigest()
usermd5s.write(md5s+'\n')
total_user += 1
except:
total_error += 1
flag_click = 0
for whoclickedsum in clickedarr:
if str(md5s) == str(whoclickedsum):
flag_click += 1
break
else:
pass
if flag_click == 0:
userclicked.write('-\n')
total_notclicked += 1
else:
userclicked.write('+\n')
mailclicked.append(data)
total_clicked += 1
flag_viewed = 0
for whoviewedsum in viewedarr:
if str(md5s) == str(whoviewedsum):
flag_viewed += 1
break
else:
pass
if flag_viewed == 0:
fixedarr.append('-')
else:
fixedarr.append('+')
if flag_click == 0 and flag_viewed != 0:
mailview.write(str(data) + '\n')
elif flag_click == 0 and flag_viewed == 0:
mailnoaction.write(str(data) + '\n')
else:
print('[-]Please, use --column [COLUMN_NAME] to give a column name!')
else:
print('[-]Please, use --sheet-name [SHEET_NAME] to give a sheet name!')
else:
print('[-]Please, use --file [FILENAME] to select an excel file!')
exit()
viewed.close()
clicked.close()
usermd5s.close()
userclicked.close()
user_click = open(dirc +"/user_clicked.txt","r")
click_line = user_click.readlines()
for ind in range(0, len(fixedarr)):
if str(fixedarr[ind]).strip() == "+" and str(click_line[ind]).strip() == "-":
userviewed.write('+\n')
total_viewed += 1
elif str(fixedarr[ind]).strip() == "+" and str(click_line[ind]).strip() == "+":
userviewed.write('+\n')
total_viewed += 1
elif str(fixedarr[ind]).strip() == "-" and str(click_line[ind]).strip() == "+":
userviewed.write('+\n')
total_viewed += 1
else:
userviewed.write('-\n')
total_noaction += 1
userviewed.close()
user_click.close()
statistics.write('Total Clicked : ' + str(total_clicked) + '\n')
statistics.write('Total NOT Clicked : ' + str(total_notclicked) + '\n')
statistics.write('Total Viewed : ' + str(total_viewed) + '\n')
statistics.write('Total No Action : ' + str(total_noaction - total_error) + '\n')
statistics.write('Total User : ' + str(total_user) + '\n')
statistics.write('Only Viewed : ' + str(total_viewed - total_clicked) + '\n')
statistics.write('Total Error : ' + str(total_error) + '\n')
print('Total Clicked : ', total_clicked)
print('Total NOT Clicked : ', total_notclicked)
print('Total Viewed : ', total_viewed)
print('Total No Action : ', total_noaction - total_error)
print('Total User : ', total_user)
print('Only Viewed : ', total_viewed - total_clicked)
print('Total Error : ', total_error)
statistics.close()
for mails in mailclicked:
mailclick.write(mails + "\n")
mailclick.close()
mailnoaction.close()
mailview.close()