Alex Sidorov пре 1 година
родитељ
комит
fc34e93d75
1 измењених фајлова са 22 додато и 18 уклоњено
  1. 22 18
      pingset.py

+ 22 - 18
pingset.py

@@ -1,4 +1,7 @@
-import os, platform, webbrowser, json
+import os
+import platform
+import webbrowser
+import json
 import subprocess as sp
 import datetime as dt
 from jinja2 import Environment, FileSystemLoader
@@ -9,49 +12,49 @@ env = Environment(
 )
 
 
-
 def get_state_ping(ip_address):
     if platform.system() in 'Linux':
         command = "ping -w 1 -c 1 %s"
     else:
         command = "ping -n 1 %s"
-    
+
     try:
         status, result = sp.getstatusoutput(
             command % (ip_address)
         )
     except ValueError:
-        return 1  
-        
+        return 1
+
     return status
 
+
 def ip_check(ip: str, count: int) -> dict:
     pbar = tqdm()
     pbar.reset(total=count)
-    
+
     count_good_ping = 0
-    time = dt.datetime.now().strftime('%H:%M:%S') 
-    
+    time = dt.datetime.now().strftime('%H:%M:%S')
+
     for _ in range(count):
         if get_state_ping(ip) == 0:
             count_good_ping += 1
-        
         pbar.update()
-    
+
     pbar.refresh()
-    
+
     return {
         "ip": ip,
         "good_ping": count_good_ping,
         "time": time
-    }        
-    
-def start(params: dict):
+    }
+
+
+def main(params: dict):
     list_result = []
     for ip in params.get('list_ip'):
         print(F"Check ip: {ip}")
         list_result.append(ip_check(ip, int(params.get('count'))))
-        
+
     template = env.get_template("template.html")
     render_template = template.render({
         "count": params.get('count'),
@@ -59,10 +62,11 @@ def start(params: dict):
         "date": dt.date.today(),
     })
 
-    html_path = os.path.join(os.path.dirname(__file__), F"report_{dt.datetime.today().timestamp()}.html")
+    html_path = os.path.join(os.path.dirname(
+        __file__), F"report_{dt.datetime.today().timestamp()}.html")
     with open(html_path, 'w') as f:
         f.write(render_template)
-        
+
     webbrowser.open(F"file://{html_path}", new=2)
 
 
@@ -72,4 +76,4 @@ if __name__ == "__main__":
         with open('settings.json') as f:
             data_from_json = json.load(f)
 
-    start(data_from_json)
+    main(data_from_json)