Created
May 25, 2017 03:04
-
-
Save BlackVikingPro/9067534f1ab7b102d8a061ab7e2a782e to your computer and use it in GitHub Desktop.
Tail.py - Python file tailer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" !- Tail.py - Python file tailer ~ By: Willy Fox - @BlackVikingPro -! """ | |
import curses, sys | |
import time, argparse | |
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import argparse | |
parser = argparse.ArgumentParser(description='Tail.py - Python file tailer ~ By: Willy Fox - @BlackVikingPro') | |
options = parser.add_argument_group('File Options') | |
options.add_argument('-f', '--file', help='File to tail', required=True) | |
options.add_argument('-c', '--count', type=int, help='Read last X lines from the file', required=True) | |
args = parser.parse_args() | |
def get_file_contents(file): | |
with open(file, 'r') as deffile: # defined file | |
contents = [] | |
for line in deffile: | |
contents.append(line.strip("\n")) | |
pass | |
pass | |
return contents | |
pass | |
if __name__ == '__main__': | |
stdscr = curses.initscr() | |
curses.noecho() | |
curses.cbreak() | |
try: | |
while True: | |
for pos, line in enumerate(get_file_contents(args.file)[-args.count:]): | |
stdscr.addstr(pos, 0, line) | |
stdscr.refresh() | |
pass | |
time.sleep(.5) | |
pass | |
pass | |
except KeyboardInterrupt: | |
print "" | |
pass | |
finally: | |
curses.echo() | |
curses.nocbreak() | |
curses.endwin() | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment