##language:zh #pragma section-numbers on ''' 对ericsson t68 手机 calendar 记录文件的报表制作 ''' <> ## 默许导航,请保留 <> {{{richter reply-to python-cn@googlegroups.com to "Python.cn@google" date nov 15, 2007 }}} = 对ericsson t68 手机 calendar 记录文件的报表制作 = '''功能介绍''' 报表的主要功能是汲取原始数据中的时间、事件内容,完成排序和格式化。这样可以以月为单位,将每个月通过手机纪录的calendar事件做成报表,察看作了哪些事,还有哪些事没完成。也许一些有同样需求的朋友可以用到:) ericsson的各种纪录的格式为.vcs,样例如下 {{{ BEGIN:VCALENDAR VERSION:1.0 BEGIN:VEVENT DTSTART:20071101T010000Z DTEND:20071101T013000Z SUMMARY;CHARSET=UTF-7:+abc- LOCATION;CHARSET=UTF-7:+UWxT+A- AALARM:20071101T005500Z CATEGORIES:VACATION END:VEVENT BEGIN:VEVENT DTSTART:20071101T015000Z DTEND:20071101T025000Z SUMMARY;CHARSET=UTF-7:+database LOCATION;CHARSET=UTF-7:+UWxT+A- AALARM:20071101T014500Z CATEGORIES:VACATION END:VEVENT BEGIN:VEVENT DTSTART:20071101T060000Z DTEND:20071101T063000Z SUMMARY;CHARSET=UTF-7:+test- AALARM:20071101T055500Z CATEGORIES:VACATION END:VEVENT BEGIN:VEVENT DTSTART:20071129T020000Z DTEND:20071230T023000Z SUMMARY;CHARSET=UTF-7:+12211212- CATEGORIES:MISCELLANEOUS END:VEVENT END:VCALENDAR }}} ''' 程序如下 ''' {{{#!python def calccolumnsize(l): """wheather the cal columns size is equals""" columns=range(len(l)) j=0 for i in l: print len(i) columns[j]=len(i) j+=1 index=0 # when column's length not equal,the writetable can't continue for iq in columns: print 'iq is ',iq if index+10: i=sourcevcs.readline() sourceli.append(i) pa_h1='BEGIN:VCALENDAR' pa_h2='VERSION:1.0' pa_t1='END:VCALENDAR' pa_b1='BEGIN:' pa_b2='DTSTART:' pa_b3='DTEND:' pa_b4='SUMMARY;CHARSET=UTF-7:' pa_b5='AALARM:' pa_b6='CATEGORIES:' pa_b7='END:' for j in sourceli: js=str(j) r=re.search(pa_h1, js) if r: headli.append(js) # print js r=re.search(pa_h2, js) if r: headli.append(js) # print js r=re.search(pa_t1, js) if r: tailli.append(js) # print js #search body1 r=re.search(pa_b1, js) if r: bodytempli1.append(js[len(pa_b1):]) # bigli.append(js) #search body2,start time r=re.search(pa_b2, js) if r: bodytempli2.append(js[len(pa_b2):-1]) #search body3,end time r=re.search(pa_b3, js) if r: bodytempli3.append(js[len(pa_b3):-1]) #search body4,summary r=re.search(pa_b4, js) if r: # bodytempli4.append(js) bodytempli4.append(decodeUTF7(js[len(pa_b4):-1])) bigli.append(bodytempli2) # bigli.append(bodytempli3) bigli.append(bodytempli4) # for debug print 'headli is ',headli print 'tailli is ', tailli # print bigli's element for i in bigli: print 'bigli ',i print len(i) return bigli def sortblock(l): """sort by starttime of per block, \the result of sorted object is list has a set of list which include \time and event summary""" sortedblock={} temp=range(len(l[0])) for i in temp: blockcontent=[] for il in l: k=il[i] # print k blockcontent.append(k) sortedblock[l[0][i]]=blockcontent for i in sortedblock: print sortedblock.get(i) s=sortedblock.keys() s.sort() # print s temp=[] for i in s: temp.append(sortedblock.get(i)) # for i in temp: # print i return temp def writetable(width1,width,gap,l): """get list,then print to table""" # check the column's size try: calccolumnsize(l) except (Exception),why: print str(why) raise why # sort the source column nl=sortblock(l) # l=sortblock(l) # calc high of per printblock # 1)mod operation for one cloumn's content # 2)to decide one cloumn's high from mod number longlist=calclongestrow(l) # blockhigh is list which has contained each block high blockhigh=[] for i in longlist: blockhigh.append(i/width+1) print 'blockhigh is ',blockhigh #fill the blackspace for summary grp line=0 for i in nl: i[0]=i[0][0:8] i[0]+='*'*(blockhigh[line]*width1-len(i[0])) i[1]+='.'*(blockhigh[line]*width-len(i[1])) line+=1 print i[0].encode('cp936') print i[1].encode('cp936') table=[] nm_block=0 for i in nl: for j in range(blockhigh[nm_block]): table.append(i[0][j*width1:(j+1)*width1]+ ' '*gap+'|'+' ' +i[1][j*width:(j+1)*width]) nm_block+=1 table.append('-'*width1+'-'*gap+'--'+'-'*width+'-'*width) print '********* final test!! *********' for i in table: print i.encode('cp936') print '********* final test end *********' }}} ''' 报表样张 ''' {{{ 0071101** | 安装kal平台(所有软件).. -------------------------------------------- 20071101** | 和肖张讲scada,含调整记d ********** | atabase........ -------------------------------------------- 20071101** | 整理两次备标我写的文章.... -------------------------------------------- 20071129** | 豆腐鸡血鸭血鸭肝虾皮,海带。去 -------------------------------------------- 20071201** | 安装kal平台(所有软件).. ********** | ............... -------------------------------------------- }}} == 反馈 == ---- [[社区项目分类]]