Skip to content

Commit

Permalink
cookiejar info
Browse files Browse the repository at this point in the history
  • Loading branch information
ksanislo committed Dec 26, 2018
1 parent 3082e15 commit 15d203c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tcc-exporter
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from http.cookiejar import LWPCookieJar
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.error import HTTPError

VERSION = '0.9.5'
VERSION = '0.9.6'
CONFIG_FILE = os.environ.get('TCC_CONFIG_FILE', 'persistent/config.yml')
PREFIX = 'https://mytotalconnectcomfort.com/'

Expand All @@ -39,9 +39,10 @@ class Client(object):
self.urlopener = urllib.request.build_opener()
self.urlopener.addheaders = [('User-Agent', 'tcc-exporter/'+VERSION)]
try:
log('DEBUG', 'Loading cookiejar: {0}'.format(config['exporter.cookiejar']))
self.cookiejar.revert(ignore_discard=True, ignore_expires=False)
except:
pass
except Exception as e:
log('ERROR', '{0} {1}: {2!r}'.format(inspect.currentframe().f_code.co_name, type(e).__name__, e.args))
self.urlopener.add_handler(urllib.request.HTTPCookieProcessor(self.cookiejar))

def login(self):
Expand All @@ -68,6 +69,7 @@ class Client(object):
if '/portal/Account/LogOff' in decoded:
log('INFO', 'Portal login successful.')
self._backoff = 0
log('DEBUG', 'Saving cookiejar: {0}'.format(config['exporter.cookiejar']))
self.cookiejar.save(ignore_discard=True, ignore_expires=False)
return True
else:
Expand Down Expand Up @@ -127,6 +129,7 @@ class Client(object):
retval = json.load(reader(data))
self._backoff = 0 # We got decodable JSON, reset the backoff.
if (os.path.getmtime(config['exporter.cookiejar']) + config['exporter.sync_interval'] <= time.time()):
log('DEBUG', 'Saving cookiejar: {0}'.format(config['exporter.cookiejar']))
self.cookiejar.save(ignore_discard=True, ignore_expires=False)
return retval
except json.JSONDecodeError as e:
Expand Down

0 comments on commit 15d203c

Please sign in to comment.