示例#1
0
 def test_load_csv(self):
     ts = TimeSheets()
     ts.time_record_type = TogglTagsTimeRecord
     ts.load_csv(data_path('test/timesheets-toggl.csv'))
     self.assertEqual(5, len(ts.records))
     self.assertEqual(0.37166666666666665, ts.records[0].duration)
     self.assertTrue(ts.records[0].task)
示例#2
0
    def test_dump_csv(self):
        ts = TimeSheets()
        ts.time_record_type = HarvestTimeRecord
        ts.load_csv(data_path('test/timesheets-harvest.csv'))

        ts.dump_csv(data_path('test/dumped-harvest.csv'), one_line=True)
        self.assertTrue(os.path.exists(data_path('test/dumped-harvest.csv')))

        # multiple line a task should become one line
        ts.load_csv(data_path('test/dumped-harvest.csv'))
        self.assertEqual(1, len(ts.records[1].notes.splitlines()))
示例#3
0
    def test_dump_csv(self):
        ts = TimeSheets()
        ts.time_record_type = TogglTimeRecord
        ts.load_csv(data_path('test/timesheets-toggl.csv'))

        ts.dump_csv(data_path('test/dumped-toggl.csv'), aggregate=True)
        self.assertTrue(os.path.exists(data_path('test/dumped-toggl.csv')))

        ts.load_csv(data_path('test/dumped-toggl.csv'))
        # Test that same task is merged
        self.assertEqual(4, len(ts.records))
        self.assertEqual(5.0, ts.records[3].duration)
示例#4
0
    def test_dump_csv(self):
        ts = TimeSheets()
        ts.time_record_type = SageOneTimeRecord
        ts.load_csv(data_path('test/timesheets-sageone.csv'))

        ts.dump_csv(data_path('test/dumped-sageone.csv'))
        self.assertTrue(os.path.exists(data_path('test/dumped-sageone.csv')))
示例#5
0
    def test_convert_to_sageone(self):
        ts = TimeSheets()
        ts.time_record_type = TogglTimeRecord
        ts.load_csv(data_path('test/timesheets-toggl.csv'))
        self.assertEqual(5, len(ts.records))

        ts.dump_csv(data_path('test/dumped-toggl-sageone.csv'),
                    target_type=SageOneTimeRecord)
        self.assertTrue(
            os.path.exists(data_path('test/dumped-toggl-sageone.csv')))

        ts.load_csv(data_path('test/dumped-toggl-sageone.csv'),
                    target_type=SageOneTimeRecord)

        self.assertEqual('11/06/2018', ts.records[0].date)
示例#6
0
    def test_convert_to_sageone(self):
        ts = TimeSheets()
        ts.time_record_type = HarvestTimeRecord
        ts.load_csv(data_path('test/timesheets-harvest.csv'))
        self.assertEqual(2, len(ts.records))

        ts.dump_csv(data_path('test/dumped-harvest-sageone.csv'),
                    target_type=SageOneTimeRecord)
        self.assertTrue(
            os.path.exists(data_path('test/dumped-harvest-sageone.csv')))
    help='CSV file as input for timesheets')
parser.add_argument(
    'csv_output',
    metavar='output_path',
    # type=argparse.FileType('w'),
    # type=basestring,
    help='CSV file as output for SageOne timesheets')


def get_record_type(type_name):
    if type_name == 'harvest':
        return HarvestTimeRecord
    elif type_name == 'toggl':
        return TogglTimeRecord
    elif type_name == 'toggl-tags':
        return TogglTagsTimeRecord
    elif type_name == 'sageone':
        return SageOneTimeRecord


args = parser.parse_args()

ts = TimeSheets()

ts.load_csv(args.csv_input, target_type=get_record_type(args.input_type))

ts.dump_csv(args.csv_output,
            target_type=get_record_type(args.output_type),
            one_line=args.one_line,
            aggregate=args.aggregate)
示例#8
0
 def test_load_csv(self):
     ts = TimeSheets()
     ts.time_record_type = HarvestTimeRecord
     ts.load_csv(data_path('test/timesheets-harvest.csv'))
     self.assertEqual(2, len(ts.records))
示例#9
0
 def test_load_csv(self):
     ts = TimeSheets()
     ts.time_record_type = SageOneTimeRecord
     ts.load_csv(data_path('test/timesheets-sageone.csv'))
     self.assertEqual(4, len(ts.records))
示例#10
0
        for d in report['days']:

            print('## {day}'.format(day=d['day']))

            for p in d['records']:

                print('### {project}'.format(project=p['project']))

                for n in p['notes']:

                    print('- {note}'.format(note=n))


args = parser.parse_args()

ts = TimeSheets()

ts.load_csv(args.csv_input, target_type=get_record_type(args.input_type))

if args.date:
    today = datetime.strptime(args.date, '%Y-%m-%d')
else:
    today = datetime.strptime(datetime.now().strftime('%Y-%m-%d'), '%Y-%m-%d')

if args.report_format == 'daily':
    # Return today
    ts.records = [r for r in ts.records if r._date == today]

    report = report_aggregate(ts)

elif args.report_format == 'weekly':