Add core-office anonymize command

for sake of demo data etc.
This commit is contained in:
Lance Edgar 2023-06-19 20:58:00 -05:00
parent b6e4ad2a21
commit 2af89f2cbf
2 changed files with 47 additions and 0 deletions

View file

@ -65,6 +65,52 @@ class Command(commands.Command):
long_description = "" 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): class ExportLaneOp(commands.ImportSubcommand):
""" """
Export "op" data from CORE Office to CORE Lane Export "op" data from CORE Office to CORE Lane

View file

@ -41,6 +41,7 @@ console_scripts =
core-office = rattail_corepos.corepos.office.commands:main core-office = rattail_corepos.corepos.office.commands:main
core_office.commands = core_office.commands =
anonymize = rattail_corepos.corepos.office.commands:Anonymize
export-csv = rattail_corepos.corepos.office.commands:ExportCSV export-csv = rattail_corepos.corepos.office.commands:ExportCSV
export-lane-op = rattail_corepos.corepos.office.commands:ExportLaneOp export-lane-op = rattail_corepos.corepos.office.commands:ExportLaneOp
import-csv = rattail_corepos.corepos.office.commands:ImportCSV import-csv = rattail_corepos.corepos.office.commands:ImportCSV