Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command line tool with basic options for parsing torrents #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ferret-guy
Copy link

@ferret-guy ferret-guy commented Feb 3, 2017

Responding to #2

creates command link hook called parse-torrent-name

example:

(parse-torrent) E:\Dropbox\Projects\parse-torrent-name>parse-torrent-name -h
usage: parse-torrent-name [-h] [-j] [-y] [-f FILENAME] torrent_name

Description of your program

positional arguments:
  torrent_name          Torrent name to parse

optional arguments:
  -h, --help            show this help message and exit
  -j, --json            Output in json format
  -y, --yaml            Output to YAML
  -f FILENAME, --file FILENAME
                        Output to file as well as command line

@@ -0,0 +1,33 @@
import argparse
Copy link
Contributor

Choose a reason for hiding this comment

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

First line for script should be the shebang line.
I.e. #!/usr/bin/python

Then the script can be executable.

import PTN

def main():
parser = argparse.ArgumentParser(description='Description of your program')
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a redundant description

parser.add_argument('-j','--json', dest="json", action='store_true', default=False, help='Output in json format')
parser.add_argument('-y','--yaml', dest="yaml", action='store_true', default=False, help='Output to YAML')
parser.add_argument('-f','--file', dest="filename", default=False, help='Output to file as well as command line')
args = vars(parser.parse_args())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you use vars()? Use args.yaml or args.json to get user input

exit(1)
elif args['json']:
try:
try: import simplejson as json
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency with the rest of the code should be in a new line.

@ferret-guy
Copy link
Author

ferret-guy commented Jul 8, 2017

@roidayan Went ahead and addressed your comments, please take a look again

@ferret-guy
Copy link
Author

@divijbindlish can you take a look at this for merging?

try:
from ruamel import yaml
output = str(yaml.dump(info, default_flow_style=False))
except ImportError, e:
except ImportError:
print "yaml module required for yaml output!\nInstall with 'pip install ruamel.yaml'"
exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

you should use sys.exit() instead of exit().

output = json.dumps(info, indent=4, sort_keys=True)
except ImportError:
print "json module required for json output!\nInstall with 'pip install simplejson' or update python to 2.6+"
exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

use sys.exit

output = str(yaml.dump(info, default_flow_style=False))
except ImportError:
print "yaml module required for yaml output!\nInstall with 'pip install ruamel.yaml'"
exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

use sys.exit

from ruamel import yaml
output = str(yaml.dump(info, default_flow_style=False))
except ImportError:
print "yaml module required for yaml output!\nInstall with 'pip install ruamel.yaml'"
Copy link
Contributor

Choose a reason for hiding this comment

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

print statement is not compatible with python3 use print() function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants