#!/usr/bin/env python
from argparse import ArgumentParser
from time import time
from datetime import datetime
from pytail import tail
from os.path import isfile
from sys import exit
from argparse import ArgumentParser
from errno import EACCES

parser = ArgumentParser(description = "This is the #tail -f# equivalent of python!")
parser.add_argument('--file', '-f', help = "The file to tail!", type = str, required = True)
parser.add_argument('--filter', '-i', help = "The filter (case-insensitive) used to match the lines you want to see!", type = str, required = False)
args = parser.parse_args()

if not isfile(args.file):
	print(f"Cannot find {args.file}")
	exit(-1)

print("#" * 30)
print(f"# Tailing file: {args.file}")

if args.filter:
	print(f"# Using filter: {args.filter}")

print("# Use <CTRL + C> to exit")
print("#" * 30)

start = time()

lines = 0
for file in tail(args.file, args.filter):
	print(f"{datetime.now()} :: {file}")
	lines += 1

total = round((time() - start),2)
print(f"# Elapsed time: {total} second(s)!")
print(f"# Speed: {round((lines / total),2)} lps (lines per second)")
print("#" * 30)
