Skip to content

Commit

Permalink
fix_bug_in_airdict
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkai88 committed Sep 17, 2015
1 parent 911ac8b commit b1acdef
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cernet/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#输出格式为月,日,时,学校,域名,种类,关键词
def cleanse(record, ipdict, parser, air):
tmp = record.split('|')
if len(tmp) < 12:
return None
host = tmp[2]
month = tmp[0][5:7]
day = tmp[0][8:10]
hour = tmp[0][11:13]
url = host + tmp[3]
try:
school = ipdict[tmp[7][:-2]]
school = ipdict[tmp[7][:-2]]
except KeyError:
return None
for hostdict in parser:
Expand All @@ -37,15 +39,15 @@ def cleanse(record, ipdict, parser, air):
t = hostdict['type']
try:
keyword = hostdict['dest'](url)
except IndexError:
except:
keyword = 'unknown'
break
if not k:
keyword = 'unknown'
t = 'unknown'
return '%s|%s|%s|%s|%s|%s|%s'%(month, day, hour, school, host, t, keyword)

return '%s|%s|%s|%s|%s|%s|%s'%(month, day, hour, school, host, t, keyword)

def stat(x, condition, features, f):
c = condition.split('=')
if len(c)!= 1:
Expand All @@ -66,6 +68,8 @@ def stat(x, condition, features, f):
output(result, filename, len(features))

def output(result, filename, n):
if len(result) == 0:
return
with open(filename, 'ab+') as final:
spamwriter = csv.writer(final, dialect='excel')
if n-1:
Expand All @@ -81,7 +85,7 @@ def output(result, filename, n):
row.append(line[1][item])
except KeyError:
row.append(0)
spamwriter.writerow(row)
spamwriter.writerow(row)
else:
for line in result:
spamwriter.writerow(list(line))
Expand Down

0 comments on commit b1acdef

Please sign in to comment.