python 統計文件

2021-08-20 03:57:59 字數 2126 閱讀 3690

#!/usr/bin/python

# -*- coding: utf-8 -*-

import datetime

import smtplib

import string

yesterday=datetime.datetime.now() - datetime.timedelta(days=1)

yesterday=yesterday.strftime('%y-%m-%d')

logfile="dataapiinfo_%s-0.log" %yesterday

sumline=0

type1=0

type2=0

type3=0

type4=0

type5=0

type6=0

type7=0

type8=0

with file(logfile,'r') as lock_f:

for line in lock_f:

if line.find("result info") > -1:

sumline=sumline+1

else:

print "no file"

if line.find("checkresult=1") > -1:

type1=type1+1

elif line.find("checkresult=2") > -1:

type2=type2+1

elif line.find("checkresult=3") > -1:

type3=type3+1

elif line.find("checkresult=4") > -1:

type4=type4+1

elif line.find("checkresult=5") > -1:

type5=type5+1

elif line.find("checkresult=6") > -1:

type6=type6+1

elif line.find("checkresult=7") > -1:

type7=type7+1

elif line.find("checkresult=8") > -1:

type8=type8+1

host = "172.16.20.102" #定義smtp主機

subject = "wyeth log 統計" #定義郵件主題

to = ["***@getui.com","***@getui.com"] #定義郵件收件人

from = "[email protected]" #定義郵件發件人

text = " %s 惠氏線下介面查詢統計如下 \n checkresult1 num %s \n checkresult2 num %s \n checkresult3 num %s \n checkresult4 num %s \n checkresult5 num %s \n checkresult6 num %s \n checkresult7 num %s \n checkresult8 num %s \n 合計 num %s \n" %(yesterday,type1,type2,type3,type4,type5,type6,type7,type8,sumline) #郵件內容

body = string.join(( #組裝sendmail方法的郵件主體內容,各段以"\r\n"進行分隔

"from: %s" % from,

"to: %s" % to,

"subject: %s" % subject ,

"",text

), "\r\n")

server = smtplib.smtp() #建立乙個smtp()物件

server.connect(host,"25") #通過connect方法連線smtp主機

server.starttls() #啟動安全傳輸模式

server.login("***","***") #郵箱賬號登入校驗

for i in range(0,2):

server.sendmail(from, to[i], body) #郵件傳送

server.quit()

統計 text html 文件型別

使用heritrix抓取的網頁儲存在jobs crawler mirror下,判斷抓取的檔案是否是text html 文件型別,只需要判斷檔案中是否含有 text html 字串,使用bufferedreader類中的readline 方法讀取檔案每一行,檢查其是否包含該串,如果有則說明是text ...

友盟統計調研文件

1.國內專業的移動應用統計分析平台。幫助移動應用開發商統計和分析流量 內容使用 使用者屬性和行為資料,以便開發商利用資料進行產品 運營 推廣策略的決策。多指標 多維度 豐富模型 2.應用趨勢 清晰展現應用的新增使用者 活躍使用者 啟動次數 版本分布 行業指標等資料,方便您從整體掌控應用的運營情況及增...

python 文件操作 Python文件操作

最近在網課中學習了python的文件操作,所以把老師上課講的都記錄了下來,作為筆記 開啟文件 可直接使用open函式,使用形式為1open 文件位址,操作形式 操作形式有以下幾個1 7r 唯讀模式 w 覆蓋寫模式 x 建立寫模式 a 追加寫模式 b 二進位制文件模式 t 文字文件模式 與r w x ...