Skip to content

Commit

Permalink
only save cookies after a login or every ~5 minutes (configurable)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksanislo committed Dec 26, 2018
1 parent b0bfd0f commit 3082e15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions persistent/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tcc.timeout: 10
exporter.host: 0.0.0.0
exporter.port: 9101
exporter.cookiejar: persistent/cookies.txt
exporter.sync_interval: 300

# This makes legacy TCC_* env variables override values from this config file.
legacy.override: True
8 changes: 6 additions & 2 deletions tcc-exporter
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import datetime
import codecs
import inspect
import json
Expand All @@ -16,7 +17,7 @@ from http.cookiejar import LWPCookieJar
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.error import HTTPError

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

Expand Down Expand Up @@ -125,7 +126,8 @@ class Client(object):
try:
retval = json.load(reader(data))
self._backoff = 0 # We got decodable JSON, reset the backoff.
self.cookiejar.save(ignore_discard=True, ignore_expires=False)
if (os.path.getmtime(config['exporter.cookiejar']) + config['exporter.sync_interval'] <= time.time()):
self.cookiejar.save(ignore_discard=True, ignore_expires=False)
return retval
except json.JSONDecodeError as e:
log('INFO', 'Portal returned invalid data.')
Expand Down Expand Up @@ -241,6 +243,8 @@ def load_config():
config['exporter.port'] = 9101
if not 'exporter.cookiejar' in config:
config['exporter.cookiejar'] = 'persistent/cookies.txt'
if not 'exporter.sync_interval' in config:
config['exporter.sync_interval'] = 300
if not 'legacy.override' in config:
config['legacy.override'] = True
# Override with config file.
Expand Down

0 comments on commit 3082e15

Please sign in to comment.