示例#1
0
def clear_all_tags(dt):
    print 'Clearing tags for day', dt.isoformat()
    entries = toggl.query('/time_entries',
                          params={
                              'start_date': get_start_for_date(dt),
                              'end_date': get_end_for_date(dt)
                          })

    # entries = z.filter(lambda e: JIGGLD_TAG in z.get('tags', e, []), entries)
    ids = list(z.pluck('id', entries))
    tags = list(z.pluck('tags', entries, default=[]))
    print tags, bcolors.okblue('-->'),
    if not ids or not any(tags):
        print bcolors.okblue('No tags to clear')
    else:
        resp = toggl.update_tags(ids, [JIGGLD_TAG, 'jiggggld'], REMOVE_TAG)
        print list(z.pluck('tags', resp['data'], default=[]))
示例#2
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'