Esempio n. 1
0
def main():
    import sys, getopt

    opts, args = getopt.getopt(sys.argv[1:], 'l:', [])

    lang = None
    for o, a in opts:
        if o == '-l':
            lang = a

    if len(args) != 1:
        print >> sys.stderr, "Should take the nid of the text on the command line!"
        sys.exit(1)
    nid = args[0]

    text = None
    if nid == '-':
        text = sys.stdin.read()
    else:
        remote = ServerInterface()
        remote.login()
        node = remote.call('node.get', int(nid))
        if node['type'] != 'content':
            print >> sys.stderr, "Node must be a content node!"
            sys.exit(1)
        if lang is None:
            lang = node['language']
        text = node['body']

    if lang is None:
        print >> sys.stderr, "Must pass -l language on the command line!"
        sys.exit(1)

    doc = parseString(text, lang)
    print doc.purehtml()
Esempio n. 2
0
def main():
    import sys, getopt

    opts, args = getopt.getopt(sys.argv[1:], 'l:', [])

    lang = None
    for o, a in opts:
        if o == '-l':
            lang = a

    if len(args) != 1:
        print >> sys.stderr, "Should take the nid of the text on the command line!"
        sys.exit(1)
    nid = args[0]

    text = None
    if nid == '-':
        text = sys.stdin.read()
    else:
        remote = ServerInterface()
        remote.login()
        node = remote.call('node.get', int(nid))
        if node['type'] != 'content':
            print >> sys.stderr, "Node must be a content node!"
            sys.exit(1)
        if lang is None:
            lang = node['language']
        text = node['body']


    if lang is None:
        print >> sys.stderr, "Must pass -l language on the command line!"
        sys.exit(1)

    doc = parseString(text, lang)
    print doc.purehtml()
Esempio n. 3
0
def main():
    import sys, getopt

    opts, args = getopt.getopt(sys.argv[1:], 'nm:l:', [])

    do_segment = False
    do_lookup = False
    do_dryRun = False
    mode = "all"
    lang = None
    for o, a in opts:
        if o == '-m':
            mode = a
        elif o == '-n':
            do_dryRun = True
        elif o == '-l':
            lang = a

    if len(args) != 1:
        print >> sys.stderr, "Should take the nid of the text on the command line!"
        sys.exit(1)
    nid = args[0]

    parts = mode.split(',')
    for p in parts:
        if p == 'all':
            do_segment = True
            do_lookup = True
        elif p == 'segment':
            do_segment = True
        elif p == 'lookup':
            do_lookup = True
        else:
            print >> sys.stderr, "Invalid mode: "+p
            sys.exit(1)

    conn = Connector()

    if nid == '-':
        content_item = { 'body': sys.stdin.read() }
    else:
        content_item = conn.get().call('node.get', int(nid))
        if content_item['type'] != 'content':
            print >> sys.stderr, "Node must be a content node!"
            sys.exit(1)
        if lang is None:
            lang = content_item['language']

    if lang is None:
        print >> sys.stderr, "Must pass -l language on the command line!"
        sys.exit(1)

    doc = parseString(content_item['body'], lang)

    if do_segment:
        doc.segmentize()

    if do_lookup:
        lookup(conn.get(), doc, lang)

    content_item['body'] = str(doc)

    if nid == '-' or do_dryRun:
        print content_item['body']
    else:
        conn.get().call('node.save', content_item)
Esempio n. 4
0
def main():
    import sys, getopt

    opts, args = getopt.getopt(sys.argv[1:], 'nm:l:', [])

    do_segment = False
    do_lookup = False
    do_dryRun = False
    mode = "all"
    lang = None
    for o, a in opts:
        if o == '-m':
            mode = a
        elif o == '-n':
            do_dryRun = True
        elif o == '-l':
            lang = a

    if len(args) != 1:
        print >> sys.stderr, "Should take the nid of the text on the command line!"
        sys.exit(1)
    nid = args[0]

    parts = mode.split(',')
    for p in parts:
        if p == 'all':
            do_segment = True
            do_lookup = True
        elif p == 'segment':
            do_segment = True
        elif p == 'lookup':
            do_lookup = True
        else:
            print >> sys.stderr, "Invalid mode: " + p
            sys.exit(1)

    conn = Connector()

    if nid == '-':
        content_item = {'body': sys.stdin.read()}
    else:
        content_item = conn.get().call('node.get', int(nid))
        if content_item['type'] != 'content':
            print >> sys.stderr, "Node must be a content node!"
            sys.exit(1)
        if lang is None:
            lang = content_item['language']

    if lang is None:
        print >> sys.stderr, "Must pass -l language on the command line!"
        sys.exit(1)

    doc = parseString(content_item['body'], lang)

    if do_segment:
        doc.segmentize()

    if do_lookup:
        lookup(conn.get(), doc, lang)

    content_item['body'] = str(doc)

    if nid == '-' or do_dryRun:
        print content_item['body']
    else:
        conn.get().call('node.save', content_item)