forked from amccollum/microtron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse.py
executable file
·31 lines (24 loc) · 852 Bytes
/
parse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import lxml.etree, lxml.html
from optparse import OptionParser
import os
import pprint
import sys
from microtron import *
def parse(argv = None):
if argv is None:
argv = sys.argv
parser = OptionParser('usage: %prog <file> <format>')
parser.add_option("-s", "--strict",
action="store_true", dest="strict", default=False,
help="be strict about parsing")
options, arguments = parser.parse_args(argv[1:])
if len(arguments) != 2:
parser.error('Incorrect number of arguments')
source_filename = os.path.abspath(arguments[0])
format = arguments[1]
tree = lxml.html.parse(source_filename)
pprint.pprint(Parser(tree, strict=options.strict).parse_format(format))
if __name__ == '__main__':
sys.exit(parse())