Skip to content

Commit 6147f88

Browse files
author
Marius Schlueter
committed
changed verbose mode too see what was cached
1 parent 16f29e0 commit 6147f88

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

pytrackunit/trackunit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self,api_key=None,verbose=False):
1111
if api_key is None:
1212
with open("api.key",encoding="utf8") as file:
1313
api_key = file.readline()
14-
self.cache = TuCache(('API',api_key))
14+
self.cache = TuCache(('API',api_key),verbose=verbose)
1515
self.verbose = verbose
1616
self.req_period = 30
1717
self.tdelta_end = None
@@ -22,8 +22,6 @@ def get(self,req):
2222
data = resp.get('list')
2323
if data is None:
2424
raise Exception("no data: "+str(resp))
25-
if self.verbose:
26-
print(req+"\t"+str(len(data)))
2725
return data
2826
def get_unitlist(self,_type=None,sort_by_hours=True):
2927
"""unitList method"""

pytrackunit/tucache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
class TuCache:
66
"""tucache class"""
7-
def __init__(self,auth=None,_dir=None):
8-
self.cache = WebCache(auth=auth,_dir=_dir)
7+
def __init__(self,auth=None,_dir=None,verbose=False):
8+
self.cache = WebCache(auth=auth,_dir=_dir,verbose=verbose)
99
def clean(self):
1010
"""deletes all cached data"""
1111
self.cache.clean()

pytrackunit/webcache.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def get_from_file(fname):
3131

3232
class WebCache:
3333
"""WebCache class"""
34-
def __init__(self,auth=None,_dir=None):
34+
def __init__(self,auth=None,_dir=None,verbose=False):
3535
self.auth = auth
36+
self.verbose = verbose
3637
if _dir is None:
3738
self.dir = "web-cache"
3839
else:
@@ -63,4 +64,9 @@ def get(self,url):
6364
with open(fname,'w',encoding='utf8') as file:
6465
file.write(resp.text)
6566
data = resp.json()
67+
if self.verbose:
68+
print(url,len(data),"W")
69+
else:
70+
if self.verbose:
71+
print(url,len(data),"C")
6672
return data

0 commit comments

Comments
 (0)