-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetData.py
More file actions
65 lines (49 loc) · 2.01 KB
/
getData.py
File metadata and controls
65 lines (49 loc) · 2.01 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
## Openn files
originalData = open('newfile.csv', "r")
uniqueIP = open('newfile2.csv', "r")
formattedData = open("formattedData.csv", "w")
## Read the first line
ipAddress = uniqueIP.readline().rstrip()
line = originalData.readline()
## Calculate time between stages
def calculateTime(currentTimeStamp):
time = 0
# Check to see if this is the first step or not
if timeStamp != []:
previousTimeStamp = timeStamp[len(timeStamp)-1]
# Convert everything into seconds
previousTimeSplit = [float(n) for n in previousTimeStamp.split(':')]
currentTimeSplit = [float(n) for n in currentTimeStamp.split(':')]
previousTimeSeconds = previousTimeSplit[0] * 3600 + previousTimeSplit[1] * 60 + previousTimeSplit[2]
currentTimeSeconds = currentTimeSplit[0] * 3600 + currentTimeSplit[1] * 60 + currentTimeSplit[2]
time = currentTimeSeconds - previousTimeSeconds
timeStamp.append(currentTimeStamp)
return str("%.6f" % time)
uniqueID = 0;
while ipAddress:
timeStamp = []
stage = -1
ipAddressSplit = ipAddress.split('.')
while line:
data = line.split(',')
if data[2] == ipAddress:
if 'root: Home page displayed.' in data[3]:
stage = 0
elif 'root: Captcha page displayed.' in data[3]:
stage = 1
elif 'hold: Captcha valid. Query: fall=Back' in data[3]:
stage = 2
elif 'get_hold' in data[3]:
stage = 3
elif 'sale: Redirect to confirm page' in data[3]:
stage = 4
if stage != -1:
formattedData.write(str(uniqueID) + ',' + ipAddressSplit[0] + ',' + calculateTime(data[1]) + ',' + str(stage) + ',' + ipAddress + ';\n')
stage = -1
line = originalData.readline()
uniqueID += 1
ipAddress = uniqueIP.readline().rstrip()
originalData.seek(0)
line = originalData.readline()
originalData.close()
uniqueIP.close()