mschieder@482: #!/usr/bin/env python3 bjoern@283: # -*- coding: utf-8 -*- bjoern@283: # bjoern@358: # (c) 2013, 2014 by Björn Ricks bernhard@535: # 2019, 2020 Intevation GmbH bernhard@535: # Author(s): bernhard@535: # * Björn Ricks bernhard@535: # * Magnus Schieder bjoern@283: # bjoern@283: # This is Free Software licensed under the terms of GPLv3 or later. bjoern@283: # For details see LICENSE coming with the source of 'getan'. bjoern@283: bjoern@373: import codecs bjoern@373: import locale bjoern@373: import sys bjoern@373: bjoern@283: from datetime import date, datetime, timedelta mschieder@463: import argparse bjoern@283: bjoern@358: from getan.template import render mschieder@526: from getan.backend import DEFAULT_DATABASE bjoern@283: bjoern@347: bjoern@283: def main(): mschieder@490: usage='getan-report [options]' mschieder@526: parser = argparse.ArgumentParser(prog='getan', usage=usage, mschieder@526: description="You can find more information at https://pypi.org/project/getan/") bjoern@283: bernhard@535: parser.add_argument('-d', '--database', metavar="DATABASE_FILE", bernhard@535: help='(default: ~/.getan/%(default)s)]', mschieder@526: default=DEFAULT_DATABASE) bernhard@535: parser.add_argument('-t', '--template', mschieder@526: help="""name of getan template (wochenbericht, mschieder@526: zeiterfassung, zeiterfassung2), mschieder@526: external templates must be stored in mschieder@526: ~/.getan/templates/ to be able to call them.""") bernhard@535: parser.add_argument('-u', '--user', help='name of user') mschieder@550: parser.add_argument('-p', '--project', help='key (sql pattern) of output project') bernhard@535: parser.add_argument('-w', '--week', type=int, help='week of year') bernhard@535: parser.add_argument('-y', '--year', type=int, help='year') bernhard@535: parser.add_argument('-c', '--lastweek', help='entries of last working week', mschieder@463: action='store_true') bernhard@535: parser.add_argument('-m', '--empty', bernhard@535: help='show projects without an entry', mschieder@463: action="store_true") bernhard@535: parser.add_argument('--encoding', help='encoding of output') bjoern@283: mschieder@463: args = parser.parse_args() mschieder@463: mschieder@463: if args.lastweek: bjoern@358: week = (datetime.now() - timedelta(7)).isocalendar()[1] bjoern@358: year = int(date.today().strftime("%Y")) bjoern@283: else: mschieder@463: year = args.year mschieder@463: week = args.week bjoern@283: mschieder@463: template_name = args.template or "wochenbericht" bjoern@283: mschieder@463: if not args.encoding: bernhard@432: encoding = locale.getdefaultlocale()[1] or "utf-8" bjoern@373: mschieder@467: sys.stdout = codecs.getwriter(encoding)(sys.stdout.detach()) bjoern@373: bernhard@431: user = None mschieder@463: if args.user: mschieder@484: user = args.user bjoern@390: mschieder@467: print(render(database=args.database, user=user, bjoern@358: template=template_name, year=year, week=week, mschieder@467: project=args.project, empty_projects=args.empty)) bjoern@283: bjoern@283: bjoern@283: if __name__ == '__main__': bjoern@283: main() bjoern@283: bjoern@283: # vim:set ts=4 sw=4 si et sta sts=4 :