Created
January 26, 2022 21:01
-
-
Save david-bla/b9fa9680f8cb96c1484526f758783911 to your computer and use it in GitHub Desktop.
check all files in current dir that ends with ".log" and count their lines.... every second
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 python3 | |
| import os | |
| import time | |
| initRanks = {} | |
| ranks = {} | |
| while True: | |
| for file in os.listdir("./"): | |
| if file[::-1][0:4][::-1] == ".log": | |
| with open(file) as f: | |
| ranks[file] = sum(1 for _ in f) | |
| if len(initRanks) == 0: | |
| initRanks = dict(ranks) | |
| sortedRanks = dict(sorted(ranks.items(), key=lambda item: item[1])) | |
| for file in sortedRanks: | |
| print(f"{file:<30}:{sortedRanks[file]-initRanks[file]:>5}\t({sortedRanks[file]:>10})") | |
| time.sleep(1) | |
| os.system('cls' if os.name == 'nt' else 'clear') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment