Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build/
dist/
random_object_id.egg-info/
venv/
.vscode/
21 changes: 21 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -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

name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
flake8 = "==2.4.0"
mccabe = "==0.3"
mock = "==1.0.1"
pep8 = "==1.5.7"
pkginfo = "==1.2.1"
py = "==1.4.26"
pyflakes = "==0.8.1"
pytest = "==2.7.0"
requests = "==2.6.1"
six = "==1.9.0"
twine = "==1.5.0"
setuptools = "*"

[requires]
python_version = "3.7"
106 changes: 106 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion random_object_id/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.4"
__version__ = "1.1.0"
25 changes: 22 additions & 3 deletions random_object_id/random_object_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
import time
import json

from argparse import ArgumentParser

Expand All @@ -18,15 +19,33 @@ def parse_args(args):
action="store_true",
dest="long_form",
help='prints the ID surrounded by ObjectId("...")')
parser.add_argument('-j', '--json',
action="store_true",
dest="json",
help='prints the IDs as a json list')
parser.add_argument('-n', '--count',
type=int,
dest="count",
default=1,
help='prints a certain amount of ids')

return parser.parse_args(args)


def main():
object_id = gen_random_object_id()
args = parse_args(sys.argv[1:])

if args.count < 1:
print("Count cannot be < 1. Your input: {}".format(args.count))
return
Comment on lines +38 to +40
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


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]
Comment on lines +42 to +45
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


if args.json:
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