-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Lucey
committed
Aug 5, 2023
1 parent
0383493
commit d2c8490
Showing
2 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import argparse | ||
import json | ||
|
||
|
||
def rm_obj_id(journey_data): | ||
del journey_data["_id"] | ||
return journey_data | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"backup_file", | ||
help="Path to the backup json file", | ||
) | ||
args = parser.parse_args() | ||
|
||
if not args.backup_file.endswith(".json"): | ||
raise ValueError("backup file must be a .json file") | ||
|
||
from via.utils import get_mongo_interface | ||
from via.settings import MONGO_RAW_JOURNEYS_COLLECTION | ||
|
||
mongo_interface = get_mongo_interface() | ||
with open(args.backup_file, "w") as fh: | ||
fh.write( | ||
json.dumps( | ||
[ | ||
rm_obj_id(journey_data) | ||
for journey_data in getattr( | ||
mongo_interface, MONGO_RAW_JOURNEYS_COLLECTION | ||
).find() | ||
] | ||
) | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |