我是hadoop的初学者,正在研究cloudera。 我在python中编写了mapper和reducer代码。
现在我想创建一个页面,其中有一个按钮,点击该按钮运行地图缩小程序并显示输出。 我该怎么做?
#!/usr/bin/python
import sys
import re
from datetime import datetime
list_of_format=['css','js','png','swf','aspx','jpeg','jpg','gif','ico']
def format(line):
for check in list_of_format :
if (line.decode('utf-8').lower()).find(check)!=-1:
return False
return True
for line in sys.stdin:
if format(line):
data = re.findall('"([^"]*)"',line)
ip=line[:line.find(" ")]
i=line.find("[")
j=line.find(" ",i)
st=line[i+1:j]
st=datetime.strptime(st,'%d/%b/%Y:%H:%M:%S')
stry=data[0]
try:
hindex=stry.index(' HTTP')
except:
pass
qindex=stry.find('?')
if qindex!=-1:
k=len(stry)
stry=''.join((stry[:qindex],stry[hindex:k]))
print "{0}\t{1}\t{2}".format(ip,st,stry )
上面是我的映射器代码。同样我写了reducer代码。 然后我运行hs mapper.py reducer.py inputfile outfile