-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAwStatEdit.py
50 lines (49 loc) · 1.84 KB
/
AwStatEdit.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
# Log File Purge Script
# For reducing the size of the AwStats log files
from os import listdir
dir_path = path.dirname(path.realpath(__file__))
chdir(dir_path)
workingdir = "/home/father/Documents/StatEdit/"
thesefiles = listdir(workingdir)
# thesefiles = ['awstats012011.peripheralarbor.com.txt']
# print(thesefiles)
for filename in thesefiles:
f = open(workingdir+filename, "r")
filedata = f.read()
f.close()
filelines = filedata.split('\n')
initiallines = len(filelines)
strt = ""
strt1 = "# URL with 404 errors - Hits - Last URL referer"
strt2 = "# URL with 404 errors - Hits - Last URL referrer"
if strt1 in filelines:
strt = strt1
elif strt2 in filelines:
strt = strt2
if strt != "":
end = "END_SIDER_404"
stidx = filelines.index(strt) - 1
edidx = filelines.index(end) + 1
filelines = filelines[:stidx] + filelines[edidx:]
print("URL spots ", stidx, edidx)
strt = "# Host - Pages - Hits - Bandwidth - Last visit date - [Start date of last visit] - [Last page of last visit]"
if strt in filelines:
end = "END_VISITOR"
stidx = filelines.index(strt) + 4 + 25
edidx = filelines.index(end)
filelines = filelines[:stidx] + filelines[edidx:]
print("Visitor spots ", stidx, edidx)
strt = "# External page referers - Pages - Hits"
if strt in filelines:
end = "END_PAGEREFS"
stidx = filelines.index(strt) + 4 + 25
edidx = filelines.index(end)
filelines = filelines[:stidx] + filelines[edidx:]
print("Pageref spots ", stidx, edidx)
finallines = len(filelines)
if initiallines > finallines:
print(filename, "reduced from", initiallines, "to", finallines, "lines")
outdata = '\n'.join(filelines)
f = open(workingdir+filename, 'w')
f.write(outdata)
f.close()