mail checker does not fail anymore, when internet connection is missing
This commit is contained in:
parent
2bf94b6d82
commit
540f3861ca
@ -5,6 +5,7 @@ import sys
|
||||
import json
|
||||
from datetime import datetime,timedelta
|
||||
import imaplib
|
||||
from statushandler import has_internet_connection
|
||||
|
||||
|
||||
class MailChecker(object):
|
||||
@ -73,20 +74,21 @@ class MailChecker(object):
|
||||
datetime.now() - timedelta(seconds=self.pause)
|
||||
|
||||
def get_connection(self):
|
||||
if not self.connection:
|
||||
try:
|
||||
self.connection = self.imap_class(self.host, self.port)
|
||||
self.connection.login(self.username, self.password)
|
||||
self.connection.select()
|
||||
except Exception:
|
||||
self.connection = None
|
||||
|
||||
try:
|
||||
self.connection.select()
|
||||
except Exception,e:
|
||||
|
||||
print e
|
||||
if not has_internet_connection():
|
||||
self.connection = None
|
||||
else:
|
||||
if not self.connection:
|
||||
try:
|
||||
self.connection = self.imap_class(self.host, self.port)
|
||||
self.connection.login(self.username, self.password)
|
||||
self.connection.select()
|
||||
except Exception:
|
||||
self.connection = None
|
||||
|
||||
try:
|
||||
self.connection.select()
|
||||
except Exception,e:
|
||||
self.connection = None
|
||||
|
||||
return self.connection
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import sys
|
||||
import json
|
||||
import urllib2
|
||||
|
||||
class I3statusHandler:
|
||||
modules = []
|
||||
@ -61,3 +62,11 @@ class I3statusHandler:
|
||||
|
||||
# and echo back new encoded json
|
||||
self.print_line(prefix+json.dumps(j))
|
||||
|
||||
|
||||
def has_internet_connection():
|
||||
try:
|
||||
response=urllib2.urlopen('http://74.125.113.99',timeout=1)
|
||||
return True
|
||||
except urllib2.URLError as err: pass
|
||||
return False
|
Loading…
Reference in New Issue
Block a user