summaryrefslogtreecommitdiff
path: root/megapixels/commands/datasets/add_uuid.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-12-13 18:13:55 +0100
committerJules Laplace <julescarbon@gmail.com>2018-12-13 18:13:55 +0100
commit3ab28a3ff3d0e1b71f123e38ce3d0df42caddc7c (patch)
tree5ec327f62304c93583d982d20e2e92e7d0fa6f57 /megapixels/commands/datasets/add_uuid.py
parentd1da6ed6b0a6911c3b24e012ea051c9253ce8479 (diff)
parentbd51b3cdf474c93b1d7c667d9e5a33159c97640a (diff)
Merge branch 'master' of github.com:adamhrv/megapixels_dev
Diffstat (limited to 'megapixels/commands/datasets/add_uuid.py')
-rw-r--r--megapixels/commands/datasets/add_uuid.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/megapixels/commands/datasets/add_uuid.py b/megapixels/commands/datasets/add_uuid.py
new file mode 100644
index 00000000..9c14c0e3
--- /dev/null
+++ b/megapixels/commands/datasets/add_uuid.py
@@ -0,0 +1,44 @@
+import click
+
+from app.settings import types
+from app.utils import click_utils
+from app.settings import app_cfg as cfg
+from app.utils.logger_utils import Logger
+
+log = Logger.getLogger()
+
+@click.command()
+@click.option('-i', '--input', 'opt_fp_in', required=True,
+ help='Input directory')
+@click.option('-o', '--output', 'opt_fp_out',
+ help='Output directory')
+@click.option('-f', '--force', 'opt_force', is_flag=True,
+ help='Force overwrite file')
+@click.pass_context
+def cli(ctx, opt_fp_in, opt_fp_out, opt_force):
+ """Appends UUID to records CSV"""
+
+ from glob import glob
+ from os.path import join
+ from pathlib import Path
+ import base64
+ import uuid
+
+ from tqdm import tqdm
+ import pandas as pd
+
+ if not opt_force and Path(opt_fp_out).exists():
+ log.error('File exists. Use "-f / --force" to overwite')
+ return
+
+ # load names
+ df_records = pd.read_csv(opt_fp_in)
+ records = df_records.to_dict('index')
+ # append a UUID to every entry
+ for idx, item in records.items():
+ records[idx]['uuid'] = uuid.uuid4()
+ # save to csv
+ df_uuid = pd.DataFrame.from_dict(list(records.values())) # ignore the indices
+ df_uuid.to_csv(opt_fp_out, index=False)
+
+ log.info('done') \ No newline at end of file