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
|
import json
|
||||||
from datetime import datetime,timedelta
|
from datetime import datetime,timedelta
|
||||||
import imaplib
|
import imaplib
|
||||||
|
from statushandler import has_internet_connection
|
||||||
|
|
||||||
|
|
||||||
class MailChecker(object):
|
class MailChecker(object):
|
||||||
@ -73,20 +74,21 @@ class MailChecker(object):
|
|||||||
datetime.now() - timedelta(seconds=self.pause)
|
datetime.now() - timedelta(seconds=self.pause)
|
||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
if not self.connection:
|
if not has_internet_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
|
|
||||||
self.connection = None
|
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
|
return self.connection
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import urllib2
|
||||||
|
|
||||||
class I3statusHandler:
|
class I3statusHandler:
|
||||||
modules = []
|
modules = []
|
||||||
@ -61,3 +62,11 @@ class I3statusHandler:
|
|||||||
|
|
||||||
# and echo back new encoded json
|
# and echo back new encoded json
|
||||||
self.print_line(prefix+json.dumps(j))
|
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