Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Conversation

@pbabbicola
Copy link

@pbabbicola pbabbicola commented May 8, 2019

Couple of features I needed: create ObjectIDs in batch, and also output them in json format.

[pbabbicola@arch-thinkpad random-object-id]$ python -m random_object_id -n 5 -j -l
[
    "ObjectId(\"5cd2a10ea7d512d2115765c9\")",
    "ObjectId(\"5cd2a10e8ed9d5153dc21293\")",
    "ObjectId(\"5cd2a10e59e01211931de464\")",
    "ObjectId(\"5cd2a10e0188318c6d992f76\")",
    "ObjectId(\"5cd2a10edbb63018fd3f480d\")"
]
[pbabbicola@arch-thinkpad random-object-id]$ python -m random_object_id -j -n 5
[
    "5cd2a1026099d0f0404d4629",
    "5cd2a102b8066112e6328426",
    "5cd2a102fdac8587510e8f70",
    "5cd2a102d6e455af9005f117",
    "5cd2a102588d3626c65310ec"
]
[pbabbicola@arch-thinkpad random-object-id]$ python -m random_object_id -n 5
5cd2a107d590e1fc2c7504af
5cd2a107f6f9e3ea4b5e960e
5cd2a10727f3e37a81213db0
5cd2a107d2ad16f37091a546
5cd2a107cb69edb367afb178

[pbabbicola@arch-thinkpad random-object-id]$ python -m random_object_id -l -j
[
    "ObjectId(\"5cd2a0f2cdec59af1be8a66d\")"
]
[pbabbicola@arch-thinkpad random-object-id]$ python -m random_object_id -j
[
    "5cd2a0f6bba7868001882e00"
]
[pbabbicola@arch-thinkpad random-object-id]$ python -m random_object_id
5cd2a0d798faf8b22c9b77ad
[pbabbicola@arch-thinkpad random-object-id]$ python -m random_object_id -l
ObjectId("5cd2a0daeabc54956ebeda0c")

Copy link
Owner

@mxr mxr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Had no idea this was opened, sorry I missed the notification...

@@ -0,0 +1,21 @@
[[source]]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the dependencies in #18 - let's undo the pipenv changes please

Comment on lines +38 to +40
if args.count < 1:
print("Count cannot be < 1. Your input: {}".format(args.count))
return
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be validated with the type= arg instead

Comment on lines +42 to +45
object_ids = [gen_random_object_id() for _ in range(args.count)]

if args.long_form:
print('ObjectId("{}")'.format(object_id))
object_ids = ['ObjectId("{}")'.format(object_id) for object_id in object_ids]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function was structured to avoid reassigning object_ids, so let's preserve that

print(json.dumps(object_ids, indent=" "))
else:
print(object_id)
[print(object_id) for object_id in object_ids]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using a list-comprehension solely to execute a side effect in a loop. Let's write an explicit loop instead

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants