Changeset 158 for table_parser


Ignore:
Timestamp:
21/11/10 02:30:03 (18 months ago)
Author:
nigel.sim
Message:

added CLI usage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • table_parser/table_parser.py

    r157 r158  
    5151    def __str__(self): 
    5252        return '<a href="%s">%s</a>'%(self.href, self.text) 
     53    def __repr__(self): 
     54        """Possible not the best repr""" 
     55        return '{"href": "%s", "text": "%s"}'%(self.href, self.text) 
    5356 
    5457# Get the item on the top of a stack 
     
    148151        self._buf += data 
    149152 
     153 
     154if __name__ == '__main__': 
     155    import sys 
     156    if len(sys.argv) == 2 and sys.argv[1] == '-t': 
     157        # Run the doctests 
     158        import doctest 
     159        doctest.testmod() 
     160    elif len(sys.argv) == 2: 
     161        # Parse the URL provided 
     162        import pprint 
     163        import urllib2 
     164        f = urllib2.urlopen(sys.argv[1]) 
     165        tp = TableParser() 
     166        tp.feed(f.read()) 
     167        f.close() 
     168        pprint.pprint(tp.doc) 
     169    else: 
     170        # Print usage 
     171        print "run doctests: <script> -t" 
     172        print "parse URL: <script> <URL>" 
Note: See TracChangeset for help on using the changeset viewer.