aboutsummaryrefslogtreecommitdiff
path: root/tools.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools.py')
-rw-r--r--tools.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools.py b/tools.py
new file mode 100644
index 0000000..862f15d
--- /dev/null
+++ b/tools.py
@@ -0,0 +1,37 @@
+#/bin/python3
+
+import sys
+import re
+import colorama
+from termcolor import colored
+colorama.init()
+
+from collections import Counter
+
+import commands
+
+def offline_counts(file):
+ counts = Counter()
+ for sentence in commands.tail(file, 4):
+ counts.update(word.strip('.,?!"\'').upper() for word in sentence.decode('utf-8').split())
+ return counts["OFFLINE"]
+
+def show_help():
+ print("{} [command]".format(sys.argv[0]))
+ print("{} Check internet status, log status in file and, if\n {}needed, restart interface.".format(sys.argv[0], " " * len(sys. argv[0])))
+ print("{} tail Follow log file like tail command".format(sys.argv[0]))
+ print("{} cat Like cat command".format(sys.argv[0]))
+
+offline = re.compile(r'.*OFFLINE.*', re.IGNORECASE)
+online = re.compile(r'.*ONLINE.*', re.IGNORECASE)
+
+def status_color(str_line):
+ if type(str_line) is bytes:
+ str_line = str_line.decode('utf-8')
+ if offline.search(str_line):
+ return colored(str_line, 'red')
+ elif online.search(str_line):
+ return colored(str_line, 'green')
+ else:
+ return str_line
+