Add internet detection to mail polybar module
This commit is contained in:
parent
75430a6316
commit
9e4dc09971
|
@ -6,6 +6,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import html
|
import html
|
||||||
|
import socket
|
||||||
from shlex import quote
|
from shlex import quote
|
||||||
|
|
||||||
ICON = ""
|
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):
|
def recent_messages(address, password):
|
||||||
obj = imaplib.IMAP4_SSL('imap.gmail.com', 993)
|
obj = imaplib.IMAP4_SSL('imap.gmail.com', 993)
|
||||||
obj.login(address, password)
|
obj.login(address, password)
|
||||||
|
@ -51,6 +61,10 @@ def ding():
|
||||||
#
|
#
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if os.path.isfile(CONFIG_FILE):
|
if os.path.isfile(CONFIG_FILE):
|
||||||
|
if not internet_is_on():
|
||||||
|
print("%{{F#{}}}{} !".format(COLOR_ERR, ICON))
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
cache = []
|
cache = []
|
||||||
if os.path.isfile(CACHE_FILE):
|
if os.path.isfile(CACHE_FILE):
|
||||||
with open(CACHE_FILE, 'r') as fp:
|
with open(CACHE_FILE, 'r') as fp:
|
||||||
|
|
Loading…
Reference in a new issue