+ if cal[-1]: cal.append('')
+
+ out.write('\r\n'.join(cal))
+
+ if not out == sys.stdout:
+ out.close()
+
+
+if __name__ == '__main__':
+ from optparse import OptionParser
+ # If the user passed us a 'stdin' argument, we'll go with that,
+ # otherwise we'll try for a url opener
+
+ parser = OptionParser('usage: %prog [options] url')
+ parser.add_option('-s', '--stdin', action='store_true', dest='stdin',
+ default=False, help='Take a calendar from standard input')
+ parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
+ default=False, help='Be verbose when rules are being applied')
+ parser.add_option('-o', '--output', dest='outfile', default='',
+ help='Specify output file (defaults to standard output)')
+
+ (options, args) = parser.parse_args()
+
+ if not args and not options.stdin:
+ parser.print_usage()
+ sys.exit(0)
+ elif not options.stdin:
+ url = args[0]
+ else:
+ url = ''
+
+ content = getContent(url, options.stdin)
+ cal = lineJoiner(content)
+ ical = applyRules(splitFields(cal), generateRules(), options.verbose)
+ output = lineFolder(joinFields(ical))
+ writeOutput(output, options.outfile)