コード例 #1
0
ファイル: main.py プロジェクト: pnw/jiggl
def for_day(dt):
    print_welcome_for_date(dt)
    entries = toggl.query('/time_entries', params={'start_date': get_start_for_date(dt),
                                                   'end_date': get_end_for_date(dt)})

    entries = z.map(replace_cologne, entries)

    valid_entries, invalid_entries = split_entries(entries)

    print_invalid_entries(invalid_entries)
    valid_entries = list(z.map(get_val, valid_entries))
    if len(valid_entries) == 0:
        print bcolors.okblue('No time entries to log for today')
        # if not raw_input('\nContinue? (Y/n)') in ('Y', 'y', ''):
        #     exit()
        return

    print_valid_entries(valid_entries)
    print_total_for_day(valid_entries)

    if raw_input('\nLog time? (Y/n) ') not in ('Y', 'y', ''):
        print bcolors.fail('Will not log time. Exiting')
        exit()

    print

    logged_entries = []  # the tickets on Toggl that need to be marked as jiggld

    tces = z.groupby(lambda tce: tce.ticket, z.map(to_tce, valid_entries))
    try:
        for ticked_id, tces in tces.iteritems():
            for tce in tces:
                print_jira_preflight(tce)
                with ensure_open_ticket(ticked_id):
                    # continue
                    try:
                        worklog = add_worklog(tce)
                    except JIRAError as e:
                        if 'non-editable workflow state' in str(e):
                            print bcolors.fail('CANNOT EDIT!')
                            exit()
                        print bcolors.fail(str(e))
                        continue
                    # print tce.entry['id']
                    logged_entries.append(tce.entry)
                    print 'WORKLOG ID', worklog.id
                    record_worklog(tce, worklog.id)
                    print_jira_postflight(tce, None)

                    # if raw_input('Good?') != '':
                    #     print bcolors.fail('Exiting')
                    #     exit()
    except Exception as e:
        print bcolors.fail(str(e))
        raise
    finally:
        if logged_entries:
            print 'Marking %s Toggl entries as tagged' % (len(logged_entries))
            resp = toggl.update_tags(list(z.pluck('id', logged_entries)), [JIGGLD_TAG])
        else:
            print 'No Toggl entries to tag as jiggld'
コード例 #2
0
ファイル: clean.py プロジェクト: pnw/jiggl

def split_description(group):
    description, entries = group
    parts = description.split(' ', 1)
    # Allow for descriptions with a Jira task identifier but no accomanying description
    if len(parts) > 1:
        return parts, entries
    return (parts[0], ''), entries


def _split_description(description):
    parts = description.split(' ', 1)
    if len(parts) > 1:
        return tuple(parts)
    return description, ''


sum_as_timedelta = lambda entries: timedelta(seconds=total_duration(entries))
total_duration = z.compose(sum, z.pluck('duration', default=0))
toggl_to_jira_datefmt = z.compose(
    jira_strftime,
    toggl_strptime,
)
get_valid_invalid = z.get([False, True], default=[])
group_by_has_error = z.groupby(has_error)
split_entries = z.compose(
    get_valid_invalid,
    group_by_has_error,
    validate_many,
)
コード例 #3
0

def split_description(group):
    description, entries = group
    parts = description.split(' ', 1)
    # Allow for descriptions with a Jira task identifier but no accomanying description
    if len(parts) > 1:
        return parts, entries
    return (parts[0], ''), entries


def _split_description(description):
    parts = description.split(' ', 1)
    if len(parts) > 1:
        return tuple(parts)
    return description, ''


sum_as_timedelta = lambda entries: timedelta(seconds=total_duration(entries))
total_duration = z.compose(sum, z.pluck('duration', default=0))
toggl_to_jira_datefmt = z.compose(
    jira_strftime,
    toggl_strptime,
)
get_valid_invalid = z.get([False, True], default=[])
group_by_has_error = z.groupby(has_error)
split_entries = z.compose(
    get_valid_invalid,
    group_by_has_error,
    validate_many,
)