from __future__ import print_function
import re, sys, glob, getopt, os

def usage():
    print('aspx2url v1.0')
    print('Usage:')
    print(sys.argv[0]+' -d -h filename(s)') 
    print('-d : Delete original file')
    print('-h : This help')

def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hd")
    except getopt.GetoptError as err:
        print(str(err))
        usage()
        sys.exit(2)
    deleteOriginal = False
    for option,value in opts:
        if option == '-h':
            usage()
            sys.exit()
        elif option == '-d':
            deleteOriginal = True
    for origFilename in args:
        with open(origFilename, "r") as f:
            html_doc = f.read()
        prog = re.compile('\<mso\:URL.*?\>(.*?),.*?\<\/mso\:URL\>', re.M)    
        result = prog.search(html_doc)
        url = result.group(1);
        filename = re.search('(.*?)\.aspx',origFilename).group(1)
        fullFilename = filename+'.url'
        with open(fullFilename, 'w') as out:
            out.write('[InternetShortcut]\n')
            out.write('URL='+url)
            out.write('\n')
        if deleteOriginal:
            os.remove(origFilename)
        
if __name__ == '__main__':
    main()

[((13, 21, 13, 54), 'getopt.getopt', 'getopt.getopt', ({(13, 35, 13, 47): 'sys.argv[1:]', (13, 49, 13, 53): '"""hd"""'}, {}), "(sys.argv[1:], 'hd')", False, 'import re, sys, glob, getopt, os\n'), ((28, 15, 28, 73), 're.compile', 're.compile', ({(28, 26, 28, 66): '"""\\\\<mso\\\\:URL.*?\\\\>(.*?),.*?\\\\<\\\\/mso\\\\:URL\\\\>"""', (28, 68, 28, 72): 're.M'}, {}), "('\\\\<mso\\\\:URL.*?\\\\>(.*?),.*?\\\\<\\\\/mso\\\\:URL\\\\>', re.M)", False, 'import re, sys, glob, getopt, os\n'), ((17, 8, 17, 19), 'sys.exit', 'sys.exit', ({(17, 17, 17, 18): '(2)'}, {}), '(2)', False, 'import re, sys, glob, getopt, os\n'), ((22, 12, 22, 22), 'sys.exit', 'sys.exit', ({}, {}), '()', False, 'import re, sys, glob, getopt, os\n'), ((38, 12, 38, 35), 'os.remove', 'os.remove', ({(38, 22, 38, 34): 'origFilename'}, {}), '(origFilename)', False, 'import re, sys, glob, getopt, os\n'), ((31, 19, 31, 56), 're.search', 're.search', ({(31, 29, 31, 42): '"""(.*?)\\\\.aspx"""', (31, 43, 31, 55): 'origFilename'}, {}), "('(.*?)\\\\.aspx', origFilename)", False, 'import re, sys, glob, getopt, os\n')]