Skip to content

Commit a18b7e6

Browse files
Add program for removing entries such as duplicates
1 parent 5517e7f commit a18b7e6

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

model/database.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ def database_init(config):
4949
def get_collection_rows(collection_name):
5050
return [row for row in database[collection_names[collection_name]].find({})]
5151

52+
def delete_by_link_id(del_link_id):
53+
"""Not for normal use.
54+
Probably should only be used from command line programs."""
55+
database[collection_names['people']].delete_one({'link_id': identification})
56+
database[collection_names['profiles']].delete_one({'link_id': identification})
57+
5258
def get_person_dict(identification):
5359
"""Read the data for a person from the database, as a dictionary."""
5460
if identification is None:

utils/deleter.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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()

utils/export-raw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def main():
2727
for row in rows:
2828
for key in row.keys():
2929
if key not in keys:
30-
keys.push(key)
30+
keys.append(key)
3131
print ("keys are", keys)
3232
with open(output_name, 'w') as csvfile:
3333
writer = csv.DictWriter(csvfile, keys)

0 commit comments

Comments
 (0)