version 0.1.1. refactored. simplified action events schema.
This commit is contained in:
parent
18ceddc9b5
commit
9457b85567
6 changed files with 32 additions and 23 deletions
|
@ -3,6 +3,13 @@ History
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
||||||
|
0.1.1 (2013-07-07)
|
||||||
|
++++++++++++++++++
|
||||||
|
|
||||||
|
- Refactored
|
||||||
|
- Simplified action events schema
|
||||||
|
|
||||||
|
|
||||||
0.0.1 (2013-07-05)
|
0.0.1 (2013-07-05)
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ Wakati.Me
|
||||||
=========
|
=========
|
||||||
|
|
||||||
Wakati.Me is a time tracking api for text editors. This is the command line
|
Wakati.Me is a time tracking api for text editors. This is the command line
|
||||||
event appender for the Wakati.Me api. You shouldn't need to directly use
|
action event appender for the Wakati.Me api. You shouldn't need to directly
|
||||||
this outside of a text editor plugin.
|
use this outside of a text editor plugin.
|
||||||
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -12,7 +12,7 @@ setup(
|
||||||
version=VERSION,
|
version=VERSION,
|
||||||
license='BSD 3 Clause',
|
license='BSD 3 Clause',
|
||||||
description=' '.join([
|
description=' '.join([
|
||||||
'Event appender for Wakati.Me, a time',
|
'Action event appender for Wakati.Me, a time',
|
||||||
'tracking api for text editors.',
|
'tracking api for text editors.',
|
||||||
]),
|
]),
|
||||||
long_description=open('README.rst').read(),
|
long_description=open('README.rst').read(),
|
||||||
|
|
|
@ -42,7 +42,7 @@ class JsonFormatter(logging.Formatter):
|
||||||
('now', self.formatTime(record, self.datefmt)),
|
('now', self.formatTime(record, self.datefmt)),
|
||||||
('version', self.version),
|
('version', self.version),
|
||||||
('plugin', self.plugin),
|
('plugin', self.plugin),
|
||||||
('timestamp', self.timestamp),
|
('time', self.timestamp),
|
||||||
('endtime', self.endtime),
|
('endtime', self.endtime),
|
||||||
('isWrite', self.isWrite),
|
('isWrite', self.isWrite),
|
||||||
('file', self.targetFile),
|
('file', self.targetFile),
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Git(BaseProject):
|
||||||
def parseConfig(self):
|
def parseConfig(self):
|
||||||
sections = {}
|
sections = {}
|
||||||
try:
|
try:
|
||||||
f = open(config, 'r')
|
f = open(self.config, 'r')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
log.exception("Exception:")
|
log.exception("Exception:")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
wakatime
|
wakatime
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
Event appender for Wakati.Me, a time tracking api for programmers.
|
Action event appender for Wakati.Me, a time tracking api for text editors.
|
||||||
|
|
||||||
:copyright: (c) 2013 Alan Hamlett.
|
:copyright: (c) 2013 Alan Hamlett.
|
||||||
:license: BSD, see LICENSE for more details.
|
:license: BSD, see LICENSE for more details.
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
__title__ = 'wakatime'
|
__title__ = 'wakatime'
|
||||||
__version__ = '0.0.1'
|
__version__ = '0.1.1'
|
||||||
__author__ = 'Alan Hamlett'
|
__author__ = 'Alan Hamlett'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__copyright__ = 'Copyright 2013 Alan Hamlett'
|
__copyright__ = 'Copyright 2013 Alan Hamlett'
|
||||||
|
@ -63,18 +63,18 @@ def parseArguments():
|
||||||
description='Wakati.Me event api appender')
|
description='Wakati.Me event api appender')
|
||||||
parser.add_argument('--file', dest='targetFile', metavar='file',
|
parser.add_argument('--file', dest='targetFile', metavar='file',
|
||||||
action=FileAction, required=True,
|
action=FileAction, required=True,
|
||||||
help='absolute path to file for current event')
|
help='absolute path to file for current action')
|
||||||
parser.add_argument('--time', dest='timestamp', metavar='time',
|
parser.add_argument('--time', dest='timestamp', metavar='time',
|
||||||
type=float,
|
type=float,
|
||||||
help='optional floating-point unix epoch timestamp; '+
|
help='optional floating-point unix epoch timestamp; '+
|
||||||
'uses current time by default')
|
'uses current time by default')
|
||||||
parser.add_argument('--endtime', dest='endtime',
|
parser.add_argument('--endtime', dest='endtime',
|
||||||
help='optional end timestamp turning this event into '+
|
help='optional end timestamp turning this action into '+
|
||||||
'a duration; if a non-duration event occurs within a '+
|
'a duration; if a non-duration action occurs within a '+
|
||||||
'duration, the duration is ignored')
|
'duration, the duration is ignored')
|
||||||
parser.add_argument('--write', dest='isWrite',
|
parser.add_argument('--write', dest='isWrite',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='note event was triggered from writing to a file')
|
help='note action was triggered from writing to a file')
|
||||||
parser.add_argument('--plugin', dest='plugin',
|
parser.add_argument('--plugin', dest='plugin',
|
||||||
help='optional text editor plugin name and version '+
|
help='optional text editor plugin name and version '+
|
||||||
'for User-Agent header')
|
'for User-Agent header')
|
||||||
|
@ -105,38 +105,38 @@ def get_api_key(configFile):
|
||||||
configFile = '~/.wakatime.conf'
|
configFile = '~/.wakatime.conf'
|
||||||
api_key = None
|
api_key = None
|
||||||
try:
|
try:
|
||||||
cf = open(os.path.expanduser('~/.wakatime'))
|
cf = open(os.path.expanduser(configFile))
|
||||||
for line in cf:
|
for line in cf:
|
||||||
line = line.split('=', 1)
|
line = line.split('=', 1)
|
||||||
if line[0] == 'api_key':
|
if line[0] == 'api_key':
|
||||||
api_key = line[1].strip()
|
api_key = line[1].strip()
|
||||||
cf.close()
|
cf.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
log.error('Could not read from config file.')
|
print('Error: Could not read from config file.')
|
||||||
return api_key
|
return api_key
|
||||||
|
|
||||||
|
|
||||||
def get_user_agent(plugin):
|
def get_user_agent(plugin):
|
||||||
user_agent = 'wakatime/%s %s' % (__version__, platform.platform())
|
user_agent = 'wakatime/%s %s' % (__version__, platform.platform())
|
||||||
if plugin:
|
if plugin:
|
||||||
user_agent = plugin+' '+user_agent
|
user_agent = user_agent+' '+plugin
|
||||||
return user_agent
|
return user_agent
|
||||||
|
|
||||||
|
|
||||||
def send_action(project_name=None, tags=None, key=None, targetFile=None,
|
def send_action(project=None, tags=None, key=None, targetFile=None,
|
||||||
timestamp=None, endtime=None, isWrite=None, plugin=None, **kwargs):
|
timestamp=None, endtime=None, isWrite=None, plugin=None, **kwargs):
|
||||||
url = 'https://www.wakati.me/api/v1/events'
|
url = 'https://www.wakatime.local/api/v1/actions'
|
||||||
log.debug('Sending event to api at %s' % url)
|
log.debug('Sending action to api at %s' % url)
|
||||||
data = {
|
data = {
|
||||||
'timestamp': timestamp,
|
'time': timestamp,
|
||||||
'file': targetFile,
|
'file': targetFile,
|
||||||
}
|
}
|
||||||
if endtime:
|
if endtime:
|
||||||
data['endtime'] = endtime
|
data['endtime'] = endtime
|
||||||
if isWrite:
|
if isWrite:
|
||||||
data['isWrite'] = isWrite
|
data['isWrite'] = isWrite
|
||||||
if project_name:
|
if project:
|
||||||
data['project'] = project_name
|
data['project'] = project
|
||||||
if tags:
|
if tags:
|
||||||
data['tags'] = tags
|
data['tags'] = tags
|
||||||
log.debug(data)
|
log.debug(data)
|
||||||
|
@ -180,11 +180,13 @@ def main():
|
||||||
if os.path.isfile(args.targetFile):
|
if os.path.isfile(args.targetFile):
|
||||||
project = find_project(args.targetFile)
|
project = find_project(args.targetFile)
|
||||||
tags = project.tags()
|
tags = project.tags()
|
||||||
if send_action(project=project, tags=tags, **vars(args)):
|
#if send_action(project=project.name(), tags=tags, **vars(args)):
|
||||||
return 0
|
# return 0
|
||||||
|
for num in range(240):
|
||||||
|
send_action(project=project.name(), tags=tags, **vars(args))
|
||||||
return 102
|
return 102
|
||||||
else:
|
else:
|
||||||
log.debug('File does not exist; ignoring this event.')
|
log.debug('File does not exist; ignoring this action.')
|
||||||
return 101
|
return 101
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue