diff --git a/rattail_corepos/corepos/office/commands.py b/rattail_corepos/corepos/office/commands.py index d15361e..ebebd29 100644 --- a/rattail_corepos/corepos/office/commands.py +++ b/rattail_corepos/corepos/office/commands.py @@ -65,6 +65,52 @@ class Command(commands.Command): long_description = "" +class Anonymize(commands.Subcommand): + """ + Update customer etc. data to make it anonymous + """ + name = 'anonymize' + description = __doc__.strip() + + def add_parser_args(self, parser): + parser.add_argument('--force', '-f', action='store_true', + help="Do not prompt for confirmation.") + + def run(self, args): + if not args.force: + self.rprint("\n[bold yellow]**WARNING** this will modify all customer (and similar) records![/bold yellow]") + value = input("\nreally want to do this? [yN] ") + if not value or not self.config.parse_bool(value): + self.stderr.write("user canceled\n") + sys.exit(1) + + try: + import names + except ImportError: + self.stderr.write("must install the `names` package first!\n\n" + "\tpip install names\n") + sys.exit(2) + + from rattail_corepos.corepos.api import make_corepos_api + from rattail_corepos.corepos.util import get_core_members + + api = make_corepos_api(self.config) + members = get_core_members(self.config, api, progress=self.progress) + + def anonymize(member, i): + data = dict(member) + cardno = data.pop('cardNo') + + for customer in data['customers']: + customer['firstName'] = names.get_first_name() + customer['lastName'] = names.get_last_name() + + api.set_member(cardno, **data) + + self.progress_loop(anonymize, members, + message="Anonymizing all member data") + + class ExportLaneOp(commands.ImportSubcommand): """ Export "op" data from CORE Office to CORE Lane diff --git a/setup.cfg b/setup.cfg index ca4eed7..a46cd4b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,6 +41,7 @@ console_scripts = core-office = rattail_corepos.corepos.office.commands:main core_office.commands = + anonymize = rattail_corepos.corepos.office.commands:Anonymize export-csv = rattail_corepos.corepos.office.commands:ExportCSV export-lane-op = rattail_corepos.corepos.office.commands:ExportLaneOp import-csv = rattail_corepos.corepos.office.commands:ImportCSV