Пример #1
0
def import_json_entries(options, args):
    o = json.load(sys.stdin)

    tag_id = model.random_id()
    for entry_dict in o:
        if 'tag_id' not in entry_dict:
            entry_dict['tag_id'] = tag_id.encode('hex')

        e = model.Entry.__import__(entry_dict)

        if tag_id and e.type == 'stop':
            tag_id = model.random_id()

    Session.commit()
Пример #2
0
def add_entry(options, args):
    # TODO: Refactor this into more sensible pieces.
    when = datetime.now()
    if options.timestamp:
        when = human_time_to_datetime(options.timestamp)

    tag = args[0]
    tag_type = None

    if ':' in tag:
        tag, tag_type = tag.split(':', 1)

    value = None
    if len(args) > 1:
        value = ' '.join(args[1:])

    if options.pipe:
        value = sys.stdin.read()

    tag_id = model.random_id()

    fn = {
        'start': tag_start,
        'stop': tag_stop,
        'duration': tag_duration,
        'pause': tag_pause,
        'resume': tag_resume,
        'note': tag_note,
        None: _tag,
    }

    fn[tag_type](when=when, tag=tag, tag_id=tag_id, value=value)

    Session.commit()
Пример #3
0
def _tag(when, tag, tag_id=None, type=None, value=None):
    value = value and unicode(value)
    tag_id = tag_id or model.random_id()
    return model.Entry.create(timestamp=when, tag=tag, tag_id=tag_id, type=type, value=value and unicode(value))