Skip to content

Commit

Permalink
added variables with global to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas-Menzel committed May 13, 2021
1 parent eb4d626 commit b27fc5c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions code/InetCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@

# Update variables according to program parameters
def apply_program_arguments():
global conn_host
global conn_port
global conn_timeout
global check_interval
global log_file
global cmd_connected
global cmd_disconnected
global beeps_connected
global beeps_disconnected

if args.host != None:
conn_host = args.host
print("Using host " + conn_host)
Expand Down Expand Up @@ -98,7 +108,7 @@ def apply_program_arguments():


# Check the internet connection
def check_connection(host=conn_host, port=conn_port, timeout=conn_timeout):
def check_connection(host='example.com', port=80, timeout=3):
try:
socket.setdefaulttimeout(timeout)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
Expand Down Expand Up @@ -138,6 +148,13 @@ def main():
global time_connected
global time_disconnected

global check_interval
global log_file
global cmd_connected
global cmd_disconnected
global beeps_connected
global beeps_disconnected

apply_program_arguments()

# Show first connection status
Expand Down Expand Up @@ -188,14 +205,18 @@ def main():


def end(signal_received, frame):
global time_connected
global time_disconnected
global time_status_change

print(" to ", end='')
print(time_pretty(time.time()), end='')
print(" - " + passed_time(time.time() - time_status_change))
print()

total_time = time_connected + time_disconnected

if total_time > 0:
if total_time > 0.0:
print("Time connected : " + passed_time(time_connected) + " - ", end='')
print(str(round((time_connected / total_time) * 100, 2)) + "%")

Expand Down

0 comments on commit b27fc5c

Please sign in to comment.