def __init__(self): # timeframe for report end_date = datetime.datetime.now() start_date = end_date - settings.timeframe # create report report_builder = Toggl(settings.api_token) workspaces = report_builder.get_workspaces() reports = [] for ws_name, ws_id in workspaces: if ws_name in settings.workspace2meta.keys(): metaproject = settings.workspace2meta[ws_name] for record in report_builder.detailed_report( ws_id, start_date, end_date): # record duration is in milliseconds # divide by 3600000 to convert to hours reports.append({ 'user': record['user'], 'team': ws_name, 'project': metaproject, 'subproject': record['project'], # example of record['start']: 2015-05-29T16:07:20+03:00 'start': record['start'][:19], 'duration': round(float(record['dur']) / 3600000, 2) }) self.df = pd.DataFrame(reports) self.df['start'] = pd.to_datetime(self.df['start']) self.total_weeks = set(self.df.set_index('start').index.week) self.first_timestamp = self.df.min(axis=1) self.projects = list( self.df.set_index('project').index.get_level_values(0).unique()) self.users = list( self.df.set_index('user').index.get_level_values(0).unique())
start_date = datetime.datetime.strptime(settings.start_date, settings.date_format) end_date = datetime.datetime.strptime(settings.end_date, settings.date_format) if today < start_date or today > end_date: parser.exit(1, "Date {0} is out of the {1}..{2} range.\n Check dates in" " settings.py\n".format( today.strftime(settings.date_format), settings.start_date, settings.end_date)) # create report report_builder = Toggl(settings.api_token) workspaces = report_builder.get_workspaces() weeks = week_list(start_date, end_date) last_records = {} # last_records[user] = last_record report_writer = csv.DictWriter( sys.stdout, ['user', 'team', 'project', 'start', 'duration']) report_writer.writeheader() for (monday, sunday) in weeks: if sunday > today: break for ws_name, ws_id in workspaces: for record in report_builder.detailed_report(ws_id, monday, sunday):
logging.debug("No date specified, using system date: %s", today.strftime(date_format)) else: try: today = datetime.datetime.strptime(args.date, date_format) except ValueError: parser.exit(1, "Invalid date\n") if today < start_date: parser.exit( 1, "Start date ({0}) has not yet come.\n Check dates in" "the settings.py\n".format(start_date)) # create report toggl = Toggl(settings.api_token) workspaces = [(w['name'], w['id']) for w in toggl.get_workspaces()] weeks = week_list(start_date, today) report_writer = csv.DictWriter( args.output, ['user', 'team', 'project', 'start', 'duration']) report_writer.writeheader() for (monday, sunday) in weeks: if sunday > today: break for ws_name, ws_id in workspaces: inactive_users = set() if args.all else \ set(u['name'] for u in toggl.get_workspace_users(ws_id, inactive=True))
parser.exit(1, "Invalid date\n") start_date = datetime.datetime.strptime(settings.start_date, settings.date_format) end_date = datetime.datetime.strptime(settings.end_date, settings.date_format) if today < start_date or today > end_date: parser.exit( 1, "Date {0} is out of the {1}..{2} range.\n Check dates in" " settings.py\n".format(today.strftime(settings.date_format), settings.start_date, settings.end_date)) # create report report_builder = Toggl(settings.api_token) workspaces = report_builder.get_workspaces() weeks = week_list(start_date, end_date) last_records = {} # last_records[user] = last_record report_writer = csv.DictWriter( sys.stdout, ['user', 'team', 'project', 'start', 'duration']) report_writer.writeheader() for (monday, sunday) in weeks: if sunday > today: break for ws_name, ws_id in workspaces: for record in report_builder.detailed_report(