-
Notifications
You must be signed in to change notification settings - Fork 2
Add pipfile for pipenv, add count and json options #16
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ build/ | |
| dist/ | ||
| random_object_id.egg-info/ | ||
| venv/ | ||
| .vscode/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| [[source]] | ||
| 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" | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "1.0.4" | ||
| __version__ = "1.1.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import os | ||
| import sys | ||
| import time | ||
| import json | ||
|
|
||
| from argparse import ArgumentParser | ||
|
|
||
|
|
@@ -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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be validated with the |
||
|
|
||
| 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function was structured to avoid reassigning |
||
|
|
||
| if args.json: | ||
| print(json.dumps(object_ids, indent=" ")) | ||
| else: | ||
| print(object_id) | ||
| [print(object_id) for object_id in object_ids] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
There was a problem hiding this comment.
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