api_url config option and --apiurl argument for sending heartbeats to a different api server
This commit is contained in:
parent
c50d7f208c
commit
f5c78ff444
1 changed files with 28 additions and 17 deletions
|
@ -172,6 +172,8 @@ def parseArguments(argv):
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
parser.add_argument('--logfile', dest='logfile',
|
parser.add_argument('--logfile', dest='logfile',
|
||||||
help='defaults to ~/.wakatime.log')
|
help='defaults to ~/.wakatime.log')
|
||||||
|
parser.add_argument('--apiurl', dest='api_url',
|
||||||
|
help='heartbeats api url; for debugging with a local server')
|
||||||
parser.add_argument('--config', dest='config',
|
parser.add_argument('--config', dest='config',
|
||||||
help='defaults to ~/.wakatime.conf')
|
help='defaults to ~/.wakatime.conf')
|
||||||
parser.add_argument('--verbose', dest='verbose', action='store_true',
|
parser.add_argument('--verbose', dest='verbose', action='store_true',
|
||||||
|
@ -238,6 +240,8 @@ def parseArguments(argv):
|
||||||
args.verbose = configs.getboolean('settings', 'debug')
|
args.verbose = configs.getboolean('settings', 'debug')
|
||||||
if not args.logfile and configs.has_option('settings', 'logfile'):
|
if not args.logfile and configs.has_option('settings', 'logfile'):
|
||||||
args.logfile = configs.get('settings', 'logfile')
|
args.logfile = configs.get('settings', 'logfile')
|
||||||
|
if not args.api_url and configs.has_option('settings', 'api_url'):
|
||||||
|
args.api_url = configs.get('settings', 'api_url')
|
||||||
|
|
||||||
return args, configs
|
return args, configs
|
||||||
|
|
||||||
|
@ -294,10 +298,14 @@ def get_user_agent(plugin):
|
||||||
|
|
||||||
|
|
||||||
def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=None,
|
def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=None,
|
||||||
timestamp=None, isWrite=None, plugin=None, offline=None,
|
timestamp=None, isWrite=None, plugin=None, offline=None, notfile=False,
|
||||||
hidefilenames=None, notfile=False, proxy=None, **kwargs):
|
hidefilenames=None, proxy=None, api_url=None, **kwargs):
|
||||||
url = 'https://wakatime.com/api/v1/heartbeats'
|
"""Sends heartbeat as POST request to WakaTime api server.
|
||||||
log.debug('Sending heartbeat to api at %s' % url)
|
"""
|
||||||
|
|
||||||
|
if not api_url:
|
||||||
|
api_url = 'https://wakatime.com/api/v1/heartbeats'
|
||||||
|
log.debug('Sending heartbeat to api at %s' % api_url)
|
||||||
data = {
|
data = {
|
||||||
'time': timestamp,
|
'time': timestamp,
|
||||||
'file': targetFile,
|
'file': targetFile,
|
||||||
|
@ -347,7 +355,7 @@ def send_heartbeat(project=None, branch=None, stats={}, key=None, targetFile=Non
|
||||||
# log time to api
|
# log time to api
|
||||||
response = None
|
response = None
|
||||||
try:
|
try:
|
||||||
response = requests.post(url, data=request_body, headers=headers,
|
response = requests.post(api_url, data=request_body, headers=headers,
|
||||||
proxies=proxies)
|
proxies=proxies)
|
||||||
except RequestException:
|
except RequestException:
|
||||||
exception_data = {
|
exception_data = {
|
||||||
|
@ -438,18 +446,21 @@ def main(argv=None):
|
||||||
heartbeat = queue.pop()
|
heartbeat = queue.pop()
|
||||||
if heartbeat is None:
|
if heartbeat is None:
|
||||||
break
|
break
|
||||||
sent = send_heartbeat(project=heartbeat['project'],
|
sent = send_heartbeat(
|
||||||
targetFile=heartbeat['file'],
|
project=heartbeat['project'],
|
||||||
timestamp=heartbeat['time'],
|
targetFile=heartbeat['file'],
|
||||||
branch=heartbeat['branch'],
|
timestamp=heartbeat['time'],
|
||||||
stats=json.loads(heartbeat['stats']),
|
branch=heartbeat['branch'],
|
||||||
key=args.key,
|
stats=json.loads(heartbeat['stats']),
|
||||||
isWrite=heartbeat['is_write'],
|
key=args.key,
|
||||||
plugin=heartbeat['plugin'],
|
isWrite=heartbeat['is_write'],
|
||||||
offline=args.offline,
|
plugin=heartbeat['plugin'],
|
||||||
hidefilenames=args.hidefilenames,
|
offline=args.offline,
|
||||||
notfile=args.notfile,
|
hidefilenames=args.hidefilenames,
|
||||||
proxy=args.proxy)
|
notfile=args.notfile,
|
||||||
|
proxy=args.proxy,
|
||||||
|
api_url=args.api_url,
|
||||||
|
)
|
||||||
if not sent:
|
if not sent:
|
||||||
break
|
break
|
||||||
return 0 # success
|
return 0 # success
|
||||||
|
|
Loading…
Reference in a new issue