-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathactivityuptime
More file actions
40 lines (35 loc) · 910 Bytes
/
activityuptime
File metadata and controls
40 lines (35 loc) · 910 Bytes
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
# -*- coding: utf-8 -*-
#读logcat文件
#查找某个字符并打印该行
import os
import sys
import datetime,time
import linecache
import codecs
logcatfilepath = os.path.split(os.path.realpath(__file__))[0]
name=input("please check in logcatname: ")
logcatname=logcatfilepath+'\\'+name+'.log'
#1.获取文件行号
#...
rowsum = len(codecs.open(logcatname, 'rU', 'utf-8').readlines())-1
#2.查找每一行是否有字符
def seachstr(strname,rownum):
str0= linecache.getline(logcatname,rownum)
if str0.find(strname)== -1 :
# print('True')
return False
else :
# print('False')
return True
#3.循环查找,然后打印某行
str1='ActivityManager: Displayed'
n=0
tmpfile=open(logcatfilepath+'\\'+name+'Activityuptime.log', 'w')
while n<rowsum:
count1 = linecache.getline(logcatname,n)
# print count
if seachstr(str1,n)==True:
# print n
# print(count1)
tmpfile.write(count1+'\n')
n=n+1