http-get.py
'''\
Get HTTP Resource.
Developer@Sonnack.com
April 2012
'''
from __future__ import print_function
from sys import stdin, stdout, stderr, argv
from os import execl, path, getcwd
from htget import htget, get_page
BasePath = r'C:\CJS\prj\Python\app'
def do_test (*args):
print('test/parameters: %d' % len(args))
hostname = args[0] if 0 < len(args) else 'sonnack.com'
pagename = args[1] if 1 < len(args) else '/logo.gif'
filename = args[2] if 2 < len(args) else path.join(BasePath,'http-get.gif')
htobj = get_page(hostname, pagename, filename)
return 'Done!'
def do_demo (*args):
print('demo/parameters: %d' % len(args))
hostname = args[0] if 0 < len(args) else 'sonnack.com'
pagename = args[1] if 1 < len(args) else '/contents.html'
filename = args[2] if 2 < len(args) else path.join(BasePath,'http-get.html')
htobj = get_page(hostname, pagename, filename)
return 'Done!'
def do_main (*args):
print('main/parameters: %d' % len(args))
if len(args) < 2:
raise RuntimeError('usage: <host> <page> [<file>]')
hostname = args[0]
pagename = args[1]
filename = args[2] if 2 < len(args) else path.join(BasePath, 'http-get.out')
htobj = get_page(hostname, pagename, filename)
return 'Done!'
def dispatch (cmd, *args):
print('command: %s' % cmd)
print('arguments: %d' % len(args))
if cmd == 'test': return do_test(*args)
if cmd == 'demo': return do_demo(*args)
if cmd == 'main': return do_main(*args)
return 'Nothing to do!'
if __name__ == '__main__':
print('autorun: %s' % argv[0])
cmd = argv[1] if 1 < len(argv) else ''
etc = argv[2:] if 2 < len(argv) else []
obj = dispatch(cmd, *etc)
print(obj)
'''eof'''