Skip to content

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

Open
ferret-guy wants to merge 2 commits into
divijbindlish:masterfrom
ferret-guy:master
Open

Added command line tool with basic options for parsing torrents#10
ferret-guy wants to merge 2 commits into
divijbindlish:masterfrom
ferret-guy:master

Conversation

@ferret-guy

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

Copy link
Copy Markdown

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

Comment thread PTN/parseTorrentName.py
@@ -0,0 +1,33 @@
import argparse

Copy link
Copy Markdown
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.

Comment thread PTN/parseTorrentName.py Outdated
import PTN

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

Copy link
Copy Markdown
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

Comment thread PTN/parseTorrentName.py Outdated
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
Copy Markdown
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

Comment thread PTN/parseTorrentName.py Outdated
exit(1)
elif args['json']:
try:
try: import simplejson as json

Copy link
Copy Markdown
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

ferret-guy commented Jul 8, 2017

Copy link
Copy Markdown
Author

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

@ferret-guy

Copy link
Copy Markdown
Author

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

Comment thread PTN/parseTorrentName.py
except ImportError, e:
except ImportError:
print "yaml module required for yaml output!\nInstall with 'pip install ruamel.yaml'"
exit(1)

Copy link
Copy Markdown
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().

Comment thread PTN/parseTorrentName.py
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use sys.exit

Comment thread PTN/parseTorrentName.py
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use sys.exit

Comment thread PTN/parseTorrentName.py
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
Copy Markdown
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