From 9e4dc0997171c26d4a727cf19683af2c8c60b303 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 6 Aug 2017 16:10:40 +0200 Subject: [PATCH] Add internet detection to mail polybar module --- os/+arch/.config/polybar/modules/mail | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/os/+arch/.config/polybar/modules/mail b/os/+arch/.config/polybar/modules/mail index 47034c01..b9eb41b1 100755 --- a/os/+arch/.config/polybar/modules/mail +++ b/os/+arch/.config/polybar/modules/mail @@ -6,6 +6,7 @@ import os import sys import re import html +import socket from shlex import quote ICON = "" @@ -18,6 +19,15 @@ COLOR_ERR = "D08770" # +def internet_is_on(): + try: + host = socket.gethostbyname("www.google.com") + s = socket.create_connection((host, 80), 2) + return True + except: + pass + return False + def recent_messages(address, password): obj = imaplib.IMAP4_SSL('imap.gmail.com', 993) obj.login(address, password) @@ -51,6 +61,10 @@ def ding(): # if __name__ == '__main__': if os.path.isfile(CONFIG_FILE): + if not internet_is_on(): + print("%{{F#{}}}{} !".format(COLOR_ERR, ICON)) + sys.exit(2) + cache = [] if os.path.isfile(CACHE_FILE): with open(CACHE_FILE, 'r') as fp: