#! /usr/bin/env python
#
# autohockey.py
#
# Created by Nephila (info at nephila dot it)
#
# A simple script to upload a given app to HockeyApp.
#
# -------------------------------------------------------------------------

import requests, json, sys, os.path
from requests.exceptions import ConnectionError
from optparse import OptionParser

UPLOAD_URL = 'https://rink.hockeyapp.net/api/2/apps/upload'

class AutoHockeyException(Exception): pass
class AutoHockeyConnectionError(AutoHockeyException): pass
class AutoHockeyBadFile(AutoHockeyException): pass
class AutoHockeyBadConfiguration(AutoHockeyException): pass

def upload(build_file, api_token='', dsym='', notify=2, notes=''):
    if not build_file:
        raise AutoHockeyBadConfiguration('Error! Build file not specified')
    if not os.path.exists(build_file):
        raise AutoHockeyBadFile('Error! {} build file doesn\'t exist'.format(build_file))
    if dsym and not os.path.exists(dsym):
        raise AutoHockeyBadFile('Error! {} .dsym.zip file doesn\'t exist'.format(dsym))
    params = {}
    params['dsym'] = dsym
    params['notify'] = notify
    params['notes'] = notes
    files = {'ipa': open(build_file, 'rb')}
    if dsym:
        files['dsym'] = open(options.dsym, 'rb')
    headers = {'X-HockeyAppToken' : api_token}
    try:
        req = requests.post(url=UPLOAD_URL, data=params, files=files, headers=headers)
        return (req.json(), req.status_code)
    except ConnectionError:
        raise AutoHockeyConnectionError('Connection error. Please try again.')


def main():
    usage = 'Usage: %prog [options] my_apk_or_ipa_or_app.zip_path'
    parser = OptionParser(usage=usage)
    parser.add_option( '-a', '--api-token', dest='api_token', default='', help='The API token.' )
    parser.add_option( '-s', '--dsym', dest='dsym', default='', help='iOS OSX ONLY, .dsym.zip corresponding to the build.')
    parser.add_option( '-d', '--notes', dest='notes', default='No notes', help='Your notes for this build.' )
    parser.add_option( '-n', '--notify', dest='notify', default=1, help='' )
    parser.add_option( '-c', '--config-file', dest='config_file', default='autohockey.cfg', help='Configuration file' )

    (options, args) = parser.parse_args()

    if len(args) == 0:
        parser.print_usage()
        exit(0)
    if len(args) == 1:
        build_file = args[0]

    params = {}
    params['api_token'] = options.api_token
    params['notify'] = options.notify
    params['notes'] = options.notes
    if options.config_file:
        print('Reading configuration...')
        if os.path.exists(options.config_file):
            json_file_content = open(options.config_file, 'r').read()
        else:
            print('Error! {} file doesn\'t exist'.format(options.config_file))
            exit(0)
        params = dict(list(params.items()) + list(json.loads(json_file_content).items()))

    print('Uploading file...')
    try:
        resp_json, status_code = upload(build_file, **params)
        print('Got {} from HockeyApp\n{}'.format(status_code, resp_json))
    except AutoHockeyException as ex:
        print('{}'.format(ex))

if __name__ == '__main__':
    main()

@@ -305,41 +305,23 @@
 ror%0A
-from optparse import OptionP
+import argp
 arse
-r
 %0A%0AUP
@@ -1524,125 +1524,207 @@
 ')%0A%0A
-%0A
 def 
-main():%0A    usage = 'Usage: %25prog %5Boptions%5D my_apk_or_ipa_or_app.zip_path'%0A    parser = OptionParser(usage=usage
+parse_args():%0A    parser = argparse.ArgumentParser(description='A simple script to upload a given app to Hockeyapp.')%0A    parser.add_argument('build', help='Path of the build you want to upload.'
 )%0A  
@@ -1740,22 +1740,17 @@
 add_
-option( '-a', 
+argument(
 '--a
@@ -1833,22 +1833,17 @@
 add_
-option( '-s', 
+argument(
 '--d
@@ -1952,22 +1952,17 @@
 add_
-option( '-d', 
+argument(
 '--n
@@ -2035,17 +2035,16 @@
  build.'
- 
 )%0A    pa
@@ -2056,22 +2056,17 @@
 add_
-option( '-n', 
+argument(
 '--n
@@ -2128,22 +2128,17 @@
 add_
-option( '-c', 
+argument(
 '--c
@@ -2225,31 +2225,18 @@
 ile'
- 
 )%0A
-%0A
    
- (options,
  args
-)
  = p
@@ -2258,104 +2258,61 @@
 s()%0A
-%0A
     
-if len(args) == 0:%0A        parser.print_usage
+return args%0A%0Adef main
 ()
+:
 %0A    
-    exit(0)%0A    if len(args) == 1:%0A    
+args = parse_args()%0A
     
@@ -2332,12 +2332,14 @@
 args
-%5B0%5D%0A
+.build
 %0A   
@@ -2377,22 +2377,19 @@
 ken'%5D = 
-option
+arg
 s.api_to
@@ -2411,30 +2411,27 @@
 'notify'%5D = 
-option
+arg
 s.notify%0A   
@@ -2449,22 +2449,19 @@
 tes'%5D = 
-option
+arg
 s.notes%0A
@@ -2467,22 +2467,19 @@
 %0A    if 
-option
+arg
 s.config
@@ -2553,22 +2553,19 @@
 .exists(
-option
+arg
 s.config
@@ -2609,22 +2609,19 @@
  = open(
-option
+arg
 s.config
@@ -2710,22 +2710,19 @@
 .format(
-option
+arg
 s.config

Use argparse