Skip to content

Instantly share code, notes, and snippets.

@david-bla
Created January 26, 2022 21:01
Show Gist options
  • Select an option

  • Save david-bla/b9fa9680f8cb96c1484526f758783911 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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