-
Notifications
You must be signed in to change notification settings - Fork 62
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
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,33 @@ | |||
import argparse |
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.
First line for script should be the shebang line.
I.e. #!/usr/bin/python
Then the script can be executable.
PTN/parseTorrentName.py
Outdated
import PTN | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Description of your program') |
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.
This is a redundant description
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()) |
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.
Why you use vars()? Use args.yaml or args.json to get user input
PTN/parseTorrentName.py
Outdated
exit(1) | ||
elif args['json']: | ||
try: | ||
try: import simplejson as json |
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.
For consistency with the rest of the code should be in a new line.
@roidayan Went ahead and addressed your comments, please take a look again |
@divijbindlish can you take a look at this for merging? |
PTN/parseTorrentName.py
Outdated
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) |
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.
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) |
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.
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) |
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.
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'" |
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.
print statement is not compatible with python3 use print() function
Responding to #2
creates command link hook called parse-torrent-name
example: