simplify coding time today function

This commit is contained in:
Alan Hamlett 2019-05-07 00:50:08 -07:00
parent 7a82f3c846
commit 23e0778392
2 changed files with 8 additions and 8 deletions

View file

@ -163,7 +163,7 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
return AUTH_ERROR if code == 401 else API_ERROR
def get_coding_time(start, end, args, use_ntlm_proxy=False):
def get_time_today(args, use_ntlm_proxy=False):
"""Get coding time from WakaTime API for given time range.
Returns total time as string or `None` when unable to fetch summary from
@ -207,8 +207,8 @@ def get_coding_time(start, end, args, use_ntlm_proxy=False):
ssl_verify = args.ssl_certs_file
params = {
'start': start,
'end': end,
'start': 'today',
'end': 'today',
}
# send request to api
@ -219,7 +219,7 @@ def get_coding_time(start, end, args, use_ntlm_proxy=False):
verify=ssl_verify)
except RequestException:
if should_try_ntlm:
return get_coding_time(start, end, args, use_ntlm_proxy=True)
return get_time_today(args, use_ntlm_proxy=True)
session_cache.delete()
if log.isEnabledFor(logging.DEBUG):
@ -233,7 +233,7 @@ def get_coding_time(start, end, args, use_ntlm_proxy=False):
except: # delete cached session when requests raises unknown exception
if should_try_ntlm:
return get_coding_time(start, end, args, use_ntlm_proxy=True)
return get_time_today(args, use_ntlm_proxy=True)
session_cache.delete()
if log.isEnabledFor(logging.DEBUG):
@ -264,7 +264,7 @@ def get_coding_time(start, end, args, use_ntlm_proxy=False):
return None, API_ERROR
else:
if should_try_ntlm:
return get_coding_time(start, end, args, use_ntlm_proxy=True)
return get_time_today(args, use_ntlm_proxy=True)
session_cache.delete()
log.debug({

View file

@ -22,7 +22,7 @@ sys.path.insert(0, os.path.dirname(pwd))
sys.path.insert(0, os.path.join(pwd, 'packages'))
from .__about__ import __version__
from .api import send_heartbeats, get_coding_time
from .api import send_heartbeats, get_time_today
from .arguments import parse_arguments
from .compat import u, json
from .constants import SUCCESS, UNKNOWN_ERROR, HEARTBEATS_PER_REQUEST
@ -43,7 +43,7 @@ def execute(argv=None):
setup_logging(args, __version__)
if args.show_time_today:
text, retval = get_coding_time('today', 'today', args)
text, retval = get_time_today(args)
if text:
print(text)
return retval