Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ksanislo committed Dec 24, 2018
1 parent d68be6d commit 9e550ae
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tcc-exporter
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import urllib.request
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.error import HTTPError

VERSION = '0.8.6'
VERSION = '0.8.7'
PREFIX = 'https://mytotalconnectcomfort.com/'
devices = list()

Expand Down Expand Up @@ -47,8 +47,10 @@ class Client(object):
self._last_login = time.mktime(time.gmtime())
data = urllib.parse.urlencode(form).encode('utf-8')
request = urllib.request.Request(PREFIX + 'portal', data, headers)
log('DEBUG', 'HTTP GET {0}'.format(PREFIX + 'portal'))
self.urlopener.open(PREFIX + 'portal') # get signin cookie
try:
log('DEBUG', 'HTTP POST {0}'.format(PREFIX + 'portal'))
data = self.urlopener.open(request) # actually sign in
decoded = data.read().decode()
if '/portal/Account/LogOff' in decoded:
Expand Down Expand Up @@ -88,7 +90,7 @@ class Client(object):
headers['Content-Type'] = 'application/json; charset=utf-8'
request = urllib.request.Request(PREFIX + path, data, headers)
try:
log('DEBUG', 'Making HTTP request for {0}'.format(PREFIX + path))
log('DEBUG', 'HTTP GET {0}'.format(PREFIX + path))
return self.urlopener.open(request) # actually fetch
except HTTPError as e:
log('INFO', 'TCC portal status: {0} - {1}'.format(e.code, e.reason))
Expand Down Expand Up @@ -218,8 +220,8 @@ def main():
except Exception as e:
log('CRITICAL', '{0} {1}: {2!r}'.format(inspect.currentframe().f_code.co_name, type(e).__name__, e.args))
return

httpd = HTTPServer(('', int(os.environ.get('TCC_EXPORTER_PORT'))), Server)
log('DEBUG', 'Starting HTTP server on port {0}'.format(os.environ.get('TCC_EXPORTER_PORT')))
httpd.serve_forever()


Expand Down

0 comments on commit 9e550ae

Please sign in to comment.