Quantcast
Channel: New Engines/Platforms — GSA SEO Forum
Viewing all articles
Browse latest Browse all 374

Split logs by message python script

$
0
0
This simple script will split your log into separate files, create folder "output" and read from "input.txt":

from typing import List


LINES_REGISTRATION = [
'registration failed',
'unknown registration status',
'registration successful'
]
LINES = [
'download failed',
]
LINES_CAPTCHA = [
'ReCaptcha v2',
]


ALL_LINES = \
LINES_REGISTRATION + LINES + LINES_CAPTCHA


def get_file_map(lines: List[str]) -> List[dict]:
return [{
'file': open(f"./output/{x}.txt", encoding='utf-8', mode='a+'),
'file_urls': open(f"./output/{x}_urls.txt", encoding='utf-8', mode='a+'),
'line': x,
} for x in lines]


if __name__ == '__main__':
file_map = get_file_map(ALL_LINES)

with open("./input.txt") as file:
for line in file:
for d in file_map:
if d['line'] in line:
d['file'].write(line)
log_split = line.split(' ')
if 'http' in log_split[-1]:
d['file_urls'].write(log_split[-1]) # It would be cool to modify SER with python

Viewing all articles
Browse latest Browse all 374

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>