|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +from __future__ import print_function |
| 4 | + |
| 5 | +import os |
| 6 | +import sys |
| 7 | +sys.path.append('model') |
| 8 | +sys.path.append(os.path.dirname(os.path.dirname(__file__))) |
| 9 | +import argparse |
| 10 | +import model.configuration as configuration |
| 11 | +import csv |
| 12 | +import model.database as database |
| 13 | + |
| 14 | +def main(): |
| 15 | + """Program to remove person entries completely. |
| 16 | + Originally meant for removing accidental duplicates.""" |
| 17 | + parser = argparse.ArgumentParser() |
| 18 | + parser.add_argument("-d", "--deletions", |
| 19 | + help="""File containing the link_ids to delete, one per line""") |
| 20 | + parser.add_argument("-f", "--for-real", |
| 21 | + action='store_true', |
| 22 | + help="""Without this flag, only do a dummy run.""") |
| 23 | + args = parser.parse_args() |
| 24 | + for_real = args.for_real |
| 25 | + config = configuration.get_config() |
| 26 | + db_config = config['database'] |
| 27 | + collection_names = db_config['collections'] |
| 28 | + database.database_init(config) |
| 29 | + count = 0 |
| 30 | + with open(args.deletions) as deletions_file: |
| 31 | + count += 1 |
| 32 | + for del_link_id in deletions_file.readlines(): |
| 33 | + if for_real: |
| 34 | + print("Deleting", del_link_id) |
| 35 | + database.delete_by_link_id(del_link_id) |
| 36 | + else: |
| 37 | + print("Would delete", del_link_id) |
| 38 | + print("Processed", count, "deletion records.") |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + main() |
0 commit comments