拍照搜题速度打点统计脚本


#!/usr/bin/env python
# -*- coding: utf-8 -*- 

'''
Created on Oct 29, 2016

@author: xwang

脚本使用说明:
1.正常拍照搜题,生成打点日志,日志格式如
10-28 17:01:25.423 10909-10909/com.wenba.bangbang D/imageUpdate: prepare \
10-28 17:01:39.162 10909-10909/com.wenba.bangbang D/imageUpdate: upload \
10-28 17:01:39.176 10909-10909/com.wenba.bangbang D/imageUpdate: e1 \
10-28 17:01:39.455 10909-10909/com.wenba.bangbang D/imageUpdate: e2 \
10-28 17:01:40.739 10909-10909/com.wenba.bangbang D/imageUpdate: onResponse \
10-28 17:01:40.810 10909-10909/com.wenba.bangbang D/imageUpdate: showSearchAnswers 
生成的日志保存到和脚本同级文件夹,命名为如“10.28.rtf”
2.新建一个空的xls文件,命名为"xixixi.xls",保存到和脚本同级目录
3.运行脚本
'''

import xlrd
import xlwt
import xlutils
from xlutils.copy import copy
import sys

currentRow = 0;

def readAndWriteXls(filename):
    f = open(filename,"r")
    lines = f.readlines()#读取全部内容
    i = 0
    for line in lines:
        #print i
        data = line.split(' ')[1][6:]
        flag = line.split(' ')[-2]
        print data,flag
        testXlwt('xixixi.xls', i, data, flag)
        i = i + 1

        # print line  

def testXlrd(filename):
    book = xlrd.open_workbook(filename)
    sh = book.sheet_by_index(0)
    #print sh.nrows, sh.ncols
    # rows = sh.row_values(2)
    return sh.nrows

def testXlwt(filename, index, data, flags):
    global currentRow
    index = index % 6
    book = xlrd.open_workbook(filename)
    sh = book.sheet_by_index(0)
    wsh = copy(book)
    wsh2 = wsh.get_sheet(0)
    wsh2.write(currentRow, index, data)
    wsh.save(filename)
    if flags == 'showSearchAnswers':
        currentRow = currentRow + 1

if __name__=='__main__':
    currentRow = testXlrd('xixixi.xls')
    print currentRow
    readAndWriteXls("10.28.rtf")

你可能感兴趣的:(拍照搜题速度打点统计脚本)