Skip to content

Commit

Permalink
Add backup tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Lucey committed Aug 5, 2023
1 parent 0383493 commit d2c8490
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
install_requires=INSTALL_REQUIRES,
entry_points={
'console_scripts': [
'pull_journeys = via.bin.pull_journeys:main',
'generate_geojson = via.bin.generate_geojson:main'
'via_pull_journeys = via.bin.pull_external_journeys:main',
'via_generate_geojson = via.bin.generate_geojson:main',
'via_backup_raw_journeys = via.bin.backup_raw_journeys:main'
]
}
)
39 changes: 39 additions & 0 deletions src/via/bin/backup_raw_journeys.py
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()

0 comments on commit d2c8490

Please sign in to comment.