Last active
November 20, 2024 22:12
-
-
Save gwbischof/eb072e7ea88151c76d80f163c7d3d1ff to your computer and use it in GitHub Desktop.
CLI to update a Bluesky Resource document spec field
This file contains hidden or 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
import argparse | |
import pymongo | |
import sys | |
def update_resource_spec(mongo_uri, resource_uid, new_spec, wet_run): | |
client = MongoClient(mongo_uri) | |
collection = client.get_database()["resource"] | |
print(f"Updating resource spec {'(dry_run)' if not wet_run else ''}") | |
if wet_run: | |
collection.update_one({"uid": resource_uid}, {"$set": {"spec": new_spec}}) | |
print( | |
"update operation: update_one({'uid': " | |
+ resource_uid | |
+ "}, {'$set': {'spec': " | |
+ new_spec | |
+ "}})" | |
) | |
def main(args=sys.argv): | |
parser = argparse.ArgumentParser( | |
description="Updates a bluesky resource document spec" | |
) | |
parser.add_argument("mongo_uri") | |
parser.add_argument("resource_uid") | |
parser.add_argument("new_spec") | |
parser.add_argument( | |
"-wet", | |
"--wet_run", | |
action="store_true", | |
help="this flag needs to be set to modify the resource document", | |
) | |
args = parser.parse_args() | |
update_resource_spec(args.mongo_uri, args.resource_uid, args.new_spec, args.wet_run) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment