CCMail_Error
unknown
python
a year ago
2.1 kB
12
Indexable
import os
import re
path = os.path.dirname(os.path.abspath(__file__))
# print(path)
filelist = []
for root, dirs, files in os.walk(path):
for file in files:
if(file.endswith(".log") or file.endswith(".log.1")):
filelist.append(os.path.join(root,file))
# print(os.path.join(root,file))
#print all the file names
total = 0
for name in filelist:
file = open(name, "r")
data = file.read()
if "Packaging of PMF with message ID '" and "Failed." and "'ReceivedByMessagingSystem[1]' to 'Error[11]'" in data:
# if "Failed." and "'ReceivedByMessagingSystem[1]' to 'Error[11]'" in data:
occurrences = data.count("'ReceivedByMessagingSystem[1]' to 'Error[11]'")
occurrencesFailed = data.count("Failed.")
occurrencesPMF = data.count("Packaging of PMF with message ID '")
# print(occurrencesPMF, occurrencesFailed, occurrences, name)
total += occurrencesFailed
print(occurrencesPMF, occurrencesFailed, occurrences, name)
print(total)
#print all the file names
# total = 0
# matches = []
# # pattern = re.compile("^Packaging of PMF with message ID '*.' is Failed.$")
# pattern = re.compile("Packaging of PMF with message ID '")
# # x = re.findall("^Packaging of PMF with message ID '.*' is Failed.$", data)
# # y = re.findall("^'ReceivedByMessagingSystem[1]' to 'Error[11]'$", data)
# # print(pattern)
# for name in filelist:
# file = open(name, "r")
# # data = file.read()
# # for line in file:
# # matches += pattern.findall(line)
# # print(matches)
# file_line = file.readline()
# while file_line:
# # print(file_line)
# matches += pattern.findall(file_line)
# # match = re.search(pattern, file_line)
# if matches == None:
# continue
# # else:
# # print(1)
# file_line = file.readline()
# file.close()
# print(matches.count)
# #Check if the string starts with "The" and ends with "Spain":
# txt = "Packaging of PMF with message ID 'XX' is Failed."
# x = re.search("^The.*Spain$", txt)
# if x:
# print("YES! We have a match!")
# else:
# print("No match")Editor is loading...
Leave a Comment