示例#1
0
    def GET(self):
        input = web.input()
        birth = input.get('birth', '').strip()
        death = input.get('death', '').strip()
        order = input.get('order', '').strip()
        if order not in ('', 'name', 'birth', 'death'):
            order = ''
        html = '''
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Merge author</title>
<style>
body { font-family: arial,helvetica,san-serif; }
th { text-align: left; }
</style>
</head>
<body>
'''
        html += '<form method="get">\n'
        html += 'Birth: <input type="text" size="7" name="birth" value="%s">\n' % web.htmlquote(birth)
        html += 'Death: <input type="text" size="7" name="death" value="%s">\n' % web.htmlquote(death)
        html += '<input type="submit" value="Search">\n</form>'

        if birth or death:
            url = 'http://openlibrary.org/query.json?type=/type/author&birth_date=%s&death_date=%s&name=' % (web.urlquote(birth), web.urlquote(death))
            data = get_all(url)
            html += result_table(data, birth, death, order)
        return html + '</body>\n</html>'
示例#2
0
    def field_table(self, input, rec_amazon, rec_marc):
        yield '<table>'
        yield '''<tr>
<th>Field</th>
<th>match</th>
<th>score</th>
<th>Amazon</th>
<th>MARC</th>
</tr>'''
        total = 0
        for field, match, score in input:
            yield '<tr>'
            yield '<td>%s</td>' % field
            yield '<td>%s</td>' % web.htmlquote(match)
            yield '<td>%s</td>' % score
            yield '<td>%s</td>' % as_html(rec_amazon.get(field, None))
#            if field == 'number_of_pages':
#                yield '<td>%s</td>' % (web.htmlquote(rec_marc['pagination']) if 'pagination' in rec_marc else '<i>pagination missing</i>')
            if field == 'authors':
                authors = rec_marc.get(field, [])
                yield '<td>%s</td>' % list_to_html(web.htmlquote(a['name']) for a in authors)
            else:
                yield '<td>%s</td>' % as_html(rec_marc.get(field, None))
            yield '</tr>'
            total += score
        yield '</table>'
        yield 'threshold %d, total: %d, ' % (threshold, total)
        yield (('match' if total >= threshold else 'no match') + '<br>')
示例#3
0
    def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)
        input = web.input()
        title = 'Tidy author'
        if 'author' in input and input.author:
            author = input.author
            name = withKey(author)['name']
            q_name = web.htmlquote(name)
            title = q_name + ' - Tidy author'
        else:
            author = None
        ret = "<html>\n<head>\n<title>%s</title>" % title

        ret += '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''

        ret += '</head><body><a name="top">'
        ret += '<form name="main" method="get"><table><tr><td align="right">Author</td><td>'
        if author:
            ret += '<input type="text" name="author" value="%s">' % web.htmlquote(author)
        else:
            ret += '<input type="text" name="author">'
        ret += '</td>'
        ret += '<td><input type="submit" value="find"></td></tr>'
        ret += '</table>'
        ret += '</form>'
        if author:
            ret += 'Author: <a href="http://openlibrary.org%s">%s</a><br>' % (author, name)
            ret += search(author, name)
        ret += "</body></html>"
        return ret
示例#4
0
    def field_table(self, input, rec_amazon, rec_marc):
        yield "<table>"
        yield """<tr>
<th>Field</th>
<th>match</th>
<th>score</th>
<th>Amazon</th>
<th>MARC</th>
</tr>"""
        total = 0
        for field, match, score in input:
            yield "<tr>"
            yield "<td>%s</td>" % field
            yield "<td>%s</td>" % web.htmlquote(match)
            yield "<td>%s</td>" % score
            yield "<td>%s</td>" % as_html(rec_amazon.get(field, None))
            if field == "authors":
                authors = rec_marc.get(field, [])
                yield "<td>%s</td>" % list_to_html(web.htmlquote(a["name"]) for a in authors)
            else:
                yield "<td>%s</td>" % as_html(rec_marc.get(field, None))
            yield "</tr>"
            total += score
        yield "</table>"
        yield "threshold %d, total: %d, " % (threshold, total)
        yield (("match" if total >= threshold else "no match") + "<br>")
示例#5
0
    def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)
        input = web.input()
        lccn = None
        oclc = None
        isbn = None
        title = 'MARC lookup'
        if 'isbn' in input and input.isbn:
            isbn = input.isbn
            if isbn == 'random':
                isbn = random_isbn()
            title = 'MARC lookup: isbn=' + isbn
        if 'lccn' in input and input.lccn:
            lccn = input.lccn
            title = 'MARC lookup: lccn=' + lccn
        if 'oclc' in input and input.oclc:
            oclc = input.oclc
            title = 'MARC lookup: oclc=' + oclc
        ret = "<html>\n<head>\n<title>%s</title>" % title
        ret += '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''

        ret += '</head><body><a name="top">'
        ret += '<form name="main" method="get"><table><tr><td align="right">ISBN</td><td>'
        if isbn:
            ret += '<input type="text" name="isbn" value="%s">' % web.htmlquote(isbn)
        else:
            ret += '<input type="text" name="isbn">'
        ret += ' or <a href="/random">random</a><br>'
        ret += '</td></tr><tr><td align="right">LCCN</td><td>'
        if lccn:
            ret += '<input type="text" name="lccn" value="%s">' % web.htmlquote(lccn)
        else:
            ret += '<input type="text" name="lccn">'
        ret += '</td></tr><tr><td align="right">OCLC</td><td>'
        if oclc:
            ret += '<input type="text" name="oclc" value="%s">' % web.htmlquote(oclc)
        else:
            ret += '<input type="text" name="oclc">'
        ret += '</td></tr>'
        ret += '<tr><td></td><td><input type="submit" value="find"></td></tr>'
        ret += '</table>'
        ret += '</form>'
        if isbn:
            ret += search('isbn', isbn)
        elif lccn:
            search('lccn', lccn)
        elif oclc:
            search('oclc', oclc)
        ret += "</body></html>"
        return ret
示例#6
0
    def GET(self):
        web.header("Content-Type", "text/html; charset=utf-8", unique=True)
        input = web.input()
        lccn = None
        oclc = None
        isbn = None
        title = "MARC lookup"
        if "isbn" in input and input.isbn:
            isbn = input.isbn
            if isbn == "random":
                isbn = random_isbn()
            title = "MARC lookup: isbn=" + isbn
        if "lccn" in input and input.lccn:
            lccn = input.lccn
            title = "MARC lookup: lccn=" + lccn
        if "oclc" in input and input.oclc:
            oclc = input.oclc
            title = "MARC lookup: oclc=" + oclc
        print "<html>\n<head>\n<title>%s</title>" % title
        print """
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>"""

        print '</head><body><a name="top">'
        print '<form name="main" method="get"><table><tr><td align="right">ISBN</td><td>'
        if isbn:
            print '<input type="text" name="isbn" value="%s">' % web.htmlquote(isbn)
        else:
            print '<input type="text" name="isbn">'
        print ' or <a href="/random">random</a><br>'
        print '</td></tr><tr><td align="right">LCCN</td><td>'
        if lccn:
            print '<input type="text" name="lccn" value="%s">' % web.htmlquote(lccn)
        else:
            print '<input type="text" name="lccn">'
        print '</td></tr><tr><td align="right">OCLC</td><td>'
        if oclc:
            print '<input type="text" name="oclc" value="%s">' % web.htmlquote(oclc)
        else:
            print '<input type="text" name="oclc">'
        print "</td></tr>",
        print '<tr><td></td><td><input type="submit" value="find"></td></tr>'
        print "</table>"
        print "</form>"
        if isbn:
            search("isbn", isbn)
        elif lccn:
            search("lccn", lccn)
        elif oclc:
            search("oclc", oclc)
        print "</body></html>"
示例#7
0
def get_web_safe_diff(text1, text2):
    lines1 = text1.splitlines(True)
    lines2 = text2.splitlines(True)
    diff = []
    s = difflib.SequenceMatcher(a=lines1, b=lines2)
    commands = s.get_opcodes()
    for command, i1, i2, j1, j2 in commands:
        if command == 'replace':
            inline_diff = diff_inline(''.join(lines1[i1:i2]), ''.join(lines2[j1:j2]))
            diff.extend(inline_diff)
        elif command == 'insert':
            diff.append(DiffTag('<ins>'))
            diff.extend(lines2[j1:j2])
            diff.append(DiffTag('</ins>'))
        elif command == 'delete':
            diff.append(DiffTag('<del>'))
            diff.extend(lines1[i1:i2])
            diff.append(DiffTag('</del>'))
    escaped_diff = []
    for s in diff:
        if isinstance(s, DiffTag):
            pass
        else:
            s = web.htmlquote(s)
        escaped_diff.append(s)
    return ''.join(escaped_diff).replace('\n', '<br>\n')
示例#8
0
 def render(self):
     out = []
     for i in self.inputs:
         if i.description != '':
             out.append('<label for="%s">%s</label><br>\n' % (i.id, web.htmlquote(i.description)))
         out.append('%s<br><br>\n' % i.render())
     return ''.join(out)
示例#9
0
    def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)

        input = web.input()
        if 'oclc' in input:
            html_oclc = web.htmlquote(input.oclc)
            print "<html>\n<head><title>OCLC to MARC: %s</title><body>" % html_oclc
        else:
            print "<html>\n<head><title>OCLC to MARC</title><body>"
        print '<form method="get">'
        print 'OCLC:'
        if 'oclc' in input:
            print '<input type="text" name="oclc" value="%s">' % html_oclc
        else:
            print '<input type="text" name="oclc">'
        print '<input type="submit" value="Find MARC">'
        print '</form>'

        if 'oclc' in input:
            print 'Searching for OCLC: %s<p>' % html_oclc
            if input.oclc in dbm:
                loc = dbm[input.oclc]
                print '<ul>'
                for l in loc.split(' '):
                    print '<li><a href="http://openlibrary.org/show-marc/%s">%s</a>' % (l, l)
                print '</ul>'
            else:
                print html_oclc, 'not found'
示例#10
0
文件: diff.py 项目: 10sr/jottit
def better_diff(a, b):
    out = []
    a, b = html2list(a), html2list(b)
    s = difflib.SequenceMatcher(None, a, b)
    for e in s.get_opcodes():
        if e[0] == "replace":
            out.append('<span class="delete">'+ web.htmlquote(''.join(a[e[1]:e[2]])) + "</span>")
            out.append('<span class="insert">'+ web.htmlquote(''.join(b[e[3]:e[4]])) + "</span>")
        elif e[0] == "delete":
            out.append('<span class="delete">'+ web.htmlquote(''.join(a[e[1]:e[2]])) + "</span>")
        elif e[0] == "insert":
            out.append('<span class="insert">'+ web.htmlquote(''.join(b[e[3]:e[4]])) + "</span>")
        elif e[0] == "equal":
                out.append(web.htmlquote(''.join(b[e[3]:e[4]])))
    out = ''.join(out)
    return re.sub(r'(\r\n|\n|\r)', '<br />\n', out)
示例#11
0
 def isbn_search(self, v):
     q = {'type': '/type/edition', 'isbn_10': v, 'title': None, 'subtitle': None}
     editions = []
     for e in query_iter(q):
         e['isbn_10'] = v
         editions.append(e)
     yield 'searching for ISBN ' + web.htmlquote(v) + ': '
     for i in self.search(editions):
         yield i
示例#12
0
 def quote_snippet(snippet):
     trans = {
         '\n': ' ',
         '{{{': '<b>',
         '}}}': '</b>',
     }
     re_trans = re.compile(r'(\n|\{\{\{|\}\}\})')
     return re_trans.sub(lambda m: trans[m.group(1)],
                         web.htmlquote(snippet))
示例#13
0
 def title_search(self, v):
     q = {'type': '/type/edition', 'isbn_10': None, 'title': v}
     editions = []
     for e in query_iter(q):
         e['title'] = v
         editions.append(e)
     yield 'searcing for title "' + web.htmlquote(v) + '": '
     for i in self.search(editions):
         yield i
示例#14
0
 def isbn_search(self, v):
     q = {'type': '/type/edition', 'isbn_10': v, 'title': None, 'subtitle': None}
     editions = []
     for e in query_iter(q):
         e['isbn_10'] = v
         editions.append(e)
     yield 'searching for ISBN ' + web.htmlquote(v) + ': '
     for i in self.search(editions):
         yield i
示例#15
0
文件: bot.py 项目: zgruza/openlibrary
    def search(self, editions):
        yield str(len(editions)) + ' editions found<p>'
        yield '<table>'
        yield '<tr><th>Key</th><th>OCLC</th><th>ISBN</th><th>title</th><th>subtitle</th></tr>'
        for e in editions:
            url = 'http://openlibrary.org' + e['key']
            title = web.htmlquote(e['title']) if e['title'] else 'no title'
            yield '<tr><td><a href="%s">%s</a></td>' % (url, e['key'])
            yield '<td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' % (
                e['oclc_numbers'], e['isbn_10'], title,
                (web.htmlquote(e['subtitle'])
                 if e.get('subtitle', None) else '<i>no subtitle</i>'))
        yield '</table><p>'

        if len(editions) == 2:
            yield '2 editions found, lets compare them<br>'
            for i in self.marc_compare(editions):
                yield i
示例#16
0
 def isbn_search(self, v):
     q = {"type": "/type/edition", "isbn_10": v, "title": None, "subtitle": None}
     editions = []
     for e in query_iter(q):
         e["isbn_10"] = v
         editions.append(e)
     yield "searching for ISBN " + web.htmlquote(v) + ": "
     for i in self.search(editions):
         yield i
示例#17
0
 def title_search(self, v):
     q = {"type": "/type/edition", "isbn_10": None, "title": v}
     editions = []
     for e in query_iter(q):
         e["title"] = v
         editions.append(e)
     yield 'searcing for title "' + web.htmlquote(v) + '": '
     for i in self.search(editions):
         yield i
示例#18
0
 def title_search(self, v):
     q = {'type': '/type/edition', 'isbn_10': None, 'title': v}
     editions = []
     for e in query_iter(q):
         e['title'] = v
         editions.append(e)
     yield 'searcing for title "' + web.htmlquote(v) + '": '
     for i in self.search(editions):
         yield i
示例#19
0
 def oclc_search(self, v):
     q = {'type': '/type/edition', 'oclc_numbers': v, 'title': None, 'subtitle': None, 'isbn_10': None}
     editions = []
     print(q)
     for e in query_iter(q):
         e['oclc_numbers'] = v
         editions.append(e)
     yield 'searching for OCLC ' + web.htmlquote(v) + ': '
     for i in self.search(editions):
         yield i
示例#20
0
 def oclc_search(self, v):
     q = {'type': '/type/edition', 'oclc_numbers': v, 'title': None, 'subtitle': None, 'isbn_10': None}
     editions = []
     print q
     for e in query_iter(q):
         e['oclc_numbers'] = v
         editions.append(e)
     yield 'searching for OCLC ' + web.htmlquote(v) + ': '
     for i in self.search(editions):
         yield i
示例#21
0
    def search(self, editions):
        yield str(len(editions)) + " editions found<p>"
        yield "<table>"
        yield "<tr><th>Key</th><th>ISBN</th><th>title</th><th>subtitle</th></tr>"
        for e in editions:
            url = "http://openlibrary.org" + e["key"]
            title = web.htmlquote(e["title"]) if e["title"] else "no title"
            yield '<tr><td><a href="%s">%s</a></td>' % (url, e["key"])
            yield "<td>%s</td><td>%s</td><td>%s</td></tr>" % (
                e["isbn_10"],
                title,
                (web.htmlquote(e["subtitle"]) if e.get("subtitle", None) else "<i>no subtitle</i>"),
            )
        yield "</table><p>"

        if len(editions) == 2:
            yield "2 editions found, lets compare them<br>"
            for i in self.compare(editions):
                yield i
示例#22
0
def inside_solr_select(params):
    params.setdefault("wt", "json")
    #solr_select = solr_select_url + '?' + '&'.join("%s=%s" % (k, unicode(v)) for k, v in params)
    solr_select = solr_select_url + "?" + urllib.urlencode(params)
    stats.begin("solr", url=solr_select)

    try:
        json_data = urlopen(solr_select).read()
    except IOError, e:
        logger.error("Unable to query search inside solr", exc_info=True)
        return {"error": web.htmlquote(str(e))}
示例#23
0
def inside_solr_select(params):
    params.setdefault("wt", "json")
    #solr_select = solr_select_url + '?' + '&'.join("%s=%s" % (k, unicode(v)) for k, v in params)
    solr_select = solr_select_url + "?" + urllib.urlencode(params)
    stats.begin("solr", url=solr_select)

    try:
        json_data = urlopen(solr_select).read()
    except IOError, e:
        logger.error("Unable to query search inside solr", exc_info=True)
        return {"error": web.htmlquote(str(e))}
示例#24
0
文件: diff.py 项目: anandology/jottit
def better_diff(a, b):
    out = []
    a, b = html2list(a), html2list(b)
    s = difflib.SequenceMatcher(None, a, b)
    for e in s.get_opcodes():
        if e[0] == "replace":
            out.append('<span class="delete">' +
                       web.htmlquote(''.join(a[e[1]:e[2]])) + "</span>")
            out.append('<span class="insert">' +
                       web.htmlquote(''.join(b[e[3]:e[4]])) + "</span>")
        elif e[0] == "delete":
            out.append('<span class="delete">' +
                       web.htmlquote(''.join(a[e[1]:e[2]])) + "</span>")
        elif e[0] == "insert":
            out.append('<span class="insert">' +
                       web.htmlquote(''.join(b[e[3]:e[4]])) + "</span>")
        elif e[0] == "equal":
            out.append(web.htmlquote(''.join(b[e[3]:e[4]])))
    out = ''.join(out)
    return re.sub(r'(\r\n|\n|\r)', '<br />\n', out)
示例#25
0
文件: db.py 项目: 10sr/jottit
def _format_changes(text, max=40):
    s = ''.join(text).strip()
    if len(s) > max:
        s = unicode(s, 'utf8')
        s = s[:max]
        s = s.strip()
        s = s+'...'
        s = s.encode('utf8')

    if not s: return 'whitespace'

    return '"<span class="src">%s</span>"' % web.htmlquote(s)
示例#26
0
def result_table(data, birth, death, order):
    html = ' %d results' % len(data)
    l = []

    def clean(i, default, field):
        if field not in i:
            return default
        if i[field] is None:
            return ''
        m = re_year.match(i[field])
        return m.group(1) if m else i[field]

    data = [{
        'key': i['key'],
        'name': i['name'],
        'birth': clean(i, birth, 'birth_date'),
        'death': clean(i, death, 'death_date'),
    } for i in data]

    base_url = web.htmlquote("?birth=%s&death=%s&order=" %
                             (web.urlquote(birth), web.urlquote(death)))
    html += '<tr>'
    html += '<th><a href="' + base_url + 'name">Name</a></th>'
    if birth:
        html += '<th>birth</th>'
    else:
        html += '<th><a href="' + base_url + 'birth">birth</a></th>'
    if death:
        html += '<th>death</th>'
    else:
        html += '<th><a href="' + base_url + 'death">death</a></th>'
    html += '</tr>'
    if order:
        data = sorted(data, key=lambda i: i[order])
    for i in data:
        html += '<tr><td><a href="http://openlibrary.org%s">%s</td><td>%s</td><td>%s</td><tr>' % (
            i['key'], web.htmlquote(i['name']), i['birth'], i['death'])
    return '<table>' + html + '</table>'
示例#27
0
class Column(object):
    def __init__(self, **kw):
        for k in kw:
            setattr(self, k, kw[k])

    _sql_name_ = lambda self, k: k

    default = None
    primary = False
    unique = False
    notnull = False

    display = lambda self, x: unicode(x)
    toxml = lambda self, obj: '>' + web.htmlquote(unicode(obj))
示例#28
0
    def search(self, editions):
        yield str(len(editions)) + ' editions found<p>'
        yield '<table>'
        yield '<tr><th>Key</th><th>OCLC</th><th>ISBN</th><th>title</th><th>subtitle</th></tr>'
        for e in editions:
            url = 'http://openlibrary.org' + e['key']
            title = web.htmlquote(e['title']) if e['title'] else 'no title'
            yield '<tr><td><a href="%s">%s</a></td>' % (url, e['key'])
            yield '<td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>' % (e['oclc_numbers'], e['isbn_10'], title, (web.htmlquote(e['subtitle']) if e.get('subtitle', None) else '<i>no subtitle</i>'))
        yield '</table><p>'

        if len(editions) == 2:
            yield '2 editions found, lets compare them<br>'
            for i in self.marc_compare(editions):
                yield i
示例#29
0
def _transform_zserv(zserv):
    zserv['html_hostname'] = web.htmlquote(zserv['hostname'])
    zserv['url_name'] = urllib.quote(zserv['name'])
    zserv['html_name'] = web.htmlquote(zserv['name'])
    zserv['nice_type'] = nice_gamemode[zserv['type']]
    zserv['nice_wads'] = []
    for wad in zserv['wads']:
        if wad in zserv['optional_wads']:
            zserv['nice_wads'].append(wad.join(['[', ']']))
        else:
            zserv['nice_wads'].append(wad)
    zserv['joined_wads'] = ', '.join(zserv['nice_wads'])
    zserv['joined_optional_wads'] = ', '.join(zserv['optional_wads'])
    zserv['joined_maps'] = ', '.join(zserv['maps'])
    zserv['nice_type'] = nice_gamemode[zserv['type']]
    if 'map' in zserv and zserv['map']:
        if 'name' in zserv['map']:
            zserv['map']['name'] = ellipsize(zserv['map']['name'])
        if 'number' in zserv['map']:
            zserv['map']['number'] = str(zserv['map']['number']).zfill(2)
    if 'remembered_stats' in zserv:
        for m in zserv['remembered_stats']:
            m['name'] = ellipsize(m['name'])
    return zserv
示例#30
0
    def GET(self):
        web.header('Content-Type', 'text/html; charset=utf-8', unique=True)
        input = web.input()
        title = 'Tidy author'
        if 'author' in input and input.author:
            author = input.author
            name = withKey(author)['name']
            q_name = web.htmlquote(name)
            title = q_name + ' - Tidy author'
        else:
            author = None
        ret = "<html>\n<head>\n<title>%s</title>" % title

        ret += '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''

        ret += '</head><body><a name="top">'
        ret += '<form name="main" method="get"><table><tr><td align="right">Author</td><td>'
        if author:
            ret += '<input type="text" name="author" value="%s">' % web.htmlquote(
                author)
        else:
            ret += '<input type="text" name="author">'
        ret += '</td>'
        ret += '<td><input type="submit" value="find"></td></tr>'
        ret += '</table>'
        ret += '</form>'
        if author:
            ret += 'Author: <a href="http://openlibrary.org%s">%s</a><br>' % (
                author, name)
            ret += search(author, name)
        ret += "</body></html>"
        return ret
示例#31
0
    def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)
        input = web.input()
        author_key = input.get('author', None)
        print "<html>\n<head>\n<title>Author fixer</title>"
        print '''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>'''

        print '</head><body><a name="top">'
        print '<form name="main" method="get">'
        if author_key:
            print '<input type="text" name="author" value="%s">' % web.htmlquote(author_key)
        else:
            print '<input type="text" name="author">'
        print '<input type="submit" value="find">'
        print '</form>'
        if author_key:
            author_search(author_key)
        print "</body></html>"
示例#32
0
    def GET(self):
        web.header('Content-Type', 'text/html; charset=utf-8', unique=True)
        input = web.input()
        author_key = input.get('author', None)
        print("<html>\n<head>\n<title>Author fixer</title>")
        print('''
<style>
th { text-align: left }
td { padding: 5px; background: #eee }
</style>''')

        print('</head><body><a name="top">')
        print('<form name="main" method="get">')
        if author_key:
            print('<input type="text" name="author" value="%s">' %
                  web.htmlquote(author_key))
        else:
            print('<input type="text" name="author">')
        print('<input type="submit" value="find">')
        print('</form>')
        if author_key:
            author_search(author_key)
        print("</body></html>")
示例#33
0
def result_table(data, birth, death, order):
    html = ' %d results' % len(data)
    l = []
    def clean(i, default, field):
        if field not in i:
            return default
        if i[field] is None:
            return ''
        m = re_year.match(i[field])
        return m.group(1) if m else i[field]

    data = [
        {
            'key': i['key'],
            'name': i['name'],
            'birth': clean(i, birth, 'birth_date'),
            'death': clean(i, death, 'death_date'),
        } for i in data]

    base_url = web.htmlquote("?birth=%s&death=%s&order=" % (web.urlquote(birth), web.urlquote(death)))
    html += '<tr>'
    html += '<th><a href="' + base_url + 'name">Name</a></th>'
    if birth:
        html += '<th>birth</th>'
    else:
        html += '<th><a href="' + base_url + 'birth">birth</a></th>'
    if death:
        html += '<th>death</th>'
    else:
        html += '<th><a href="' + base_url + 'death">death</a></th>'
    html += '</tr>'
    if order:
        data = sorted(data, key=lambda i:i[order])
    for i in data:
        html += '<tr><td><a href="http://openlibrary.org%s">%s</td><td>%s</td><td>%s</td><tr>' % (i['key'], web.htmlquote(i['name']), i['birth'], i['death'])
    return '<table>' + html + '</table>'
示例#34
0
def html_quote(html):
    return web.htmlquote(html)
示例#35
0
def quote_snippet(snippet):
    return re_trans.sub(lambda m: trans[m.group(1)], web.htmlquote(snippet))
示例#36
0
文件: misc.py 项目: alexksikes/mailer
def html_quote(html):
    return web.htmlquote(url)
示例#37
0
文件: project.py 项目: hraban/munca
def nl2br(txt):
    return web.htmlquote(txt).replace("\r\n", "<br>").replace("\n", "<br>")
示例#38
0
def textbox(name, input):
    if name in input:
        return '<input type="text" name="%s" value="%s" size="60">' % (
            name, web.htmlquote(input[name]))
    else:
        return '<input type="text" name="%s" size="60">' % (name)
示例#39
0
def textbox(name, input):
    if name in input:
        return '<input type="text" name="%s" value="%s" size="60">' % (name, web.htmlquote(input[name]))
    else:
        return '<input type="text" name="%s" size="60">' % (name)
示例#40
0
def long_tag(text, maxLength=12):
    tag = long_str(text, maxLength)
    if tag == text:
        return web.htmlquote(text)
    else:
        return u'<abbr title="%s">%s</abbr>' % (web.htmlquote(text), web.htmlquote(tag))
示例#41
0
def xmlquote(dat):
    xml = xmldom.parseString(dat)
    ret = xml.toprettyxml(indent = '  ', newl = '\n')
    return web.htmlquote(ret).replace('\n', '<br/>')
示例#42
0
 def text_box(self, k):
     if self.input[k]:
         v = web.htmlquote(self.input[k])
         return '<input type="text" name="%s" value="%s">' % (k, v)
     else:
         return '<input type="text" name="%s">' % k
示例#43
0
def quote_snippet(snippet):
    return re_trans.sub(lambda m: trans[m.group(1)], web.htmlquote(snippet))
示例#44
0
def search(author, name):
    book_fields = ('title_prefix', 'title');
    q = { 'type': '/type/edition', 'authors': author, 'title_prefix': None, 'title': None, 'isbn_10': None}
    found = list(query_iter(q))
    db_author = ''
    names = set([name])
    t = ''
    books = []
    for e in found:
        locs = set()
        for i in e['isbn_10'] or []:
            locs.update(search_query('isbn', i))
        if not locs:
            books.append((e['key'], (e['title_prefix'] or '') + e['title'], None, []))
            continue
        found = data_from_marc(locs, name)
        if len(found) != 1:
            locs = []
            for i in found.values():
                locs.append(i)
            books.append((e['key'], (e['title_prefix'] or '') + e['title'], None, locs))
            continue
        marc_author = found.keys()[0]
        locs = found.values()[0]
        names.update(marc_author[0:2])
        books.append((e['key'], (e['title_prefix'] or '') + e['title'], marc_author, locs))

    authors = []
    names2 = set()
    for n in names:
        if ', ' in n:
            continue
        i = n.rfind(' ')
        names2.add("%s, %s" % (n[i+1:], n[:i]))
    names.update(names2)

    for n in names:
        for a in author_search(n):
            authors.append(a)

    for a in authors:
        q = {
            'type': '/type/edition',
            'authors': a['key'],
            'title_prefix': None,
            'title': None,
            'isbn_10': None
        }
        a['editions'] = list(query_iter(q))

    author_map = {}

    for key, title, a, locs in books:
        t += '<tr><td><a href="http://openlibrary.org' + key + '">' + web.htmlquote(title) + '</a>'
        t += '<br>' + ', '.join('<a href="http://openlibrary.org/show-marc/%s">%s</a>' % (i, i) for i in locs) + '</td>'
#        t += '<td>' + web.htmlquote(repr(a[2])) + '</td>'
        if a:
            if a[2] not in author_map:
                dates = {'birth_date': a[2][0], 'death_date': a[2][1], 'dates': a[2][2]}
                db_match = [db for db in authors if author_dates_match(dates, db)]
                author_map[a[2]] = db_match[0] if len(db_match) == 1 else None

            match = author_map[a[2]]
            if match:
                t += '<td><a href="http://openlibrary.org%s">%s-%s</a></td>' % (match['key'], match['birth_date'] or '', match['death_date'] or '')
            else:
                t += '<td>%s-%s (no match)</td>' % (dates['birth_date'] or '', dates['death_date'] or '')
        t += '</tr>\n'

    ret = ''
    if authors:
        ret += '<ul>'
        for a in authors:
            ret += '<li><a href="http://openlibrary.org%s">%s</a> (%s-%s) %d editions' % (a['key'], web.htmlquote(name), a['birth_date'] or '', a['death_date'] or '', len(a['editions']))
        ret += '</ul>'

    return ret + '<table>' + t + '</table>'
示例#45
0
        description='Reply to: '),
    form.Textbox('to', 
        form.notnull,
        description='To: ',
        pre='<label class="help" for="to">Use the template variable email e.g. $email specified by the SQL query.</label>'),
    form.Textbox('subject', 
        form.notnull,
        description='Subject: ',
        pre='<label class="help" for="to">Use any template variable e.g. $variable_name specified by the SQL query.</label>'),
    form.Textarea('message', 
        form.notnull,
        description='Message: ',
        pre='<label class="help" for="to">Use any template variable e.g. $variable_name specified by the SQL query.</label>'),
    form.Checkbox('send_copy',
        description='',
        post='<span>Send a copy to:</span> <span>%s</span>' % web.htmlquote(config.mail_bcc)),
    form.Checkbox('force_resend',
        description='',
        post='<span>Force resend to previously emailed recipients.</span>'))
    
class index:
    def GET(self):
        return view.base(view.index(view.sendmail_form(sendmail_form())))

class send:    
    def POST(self):
        f = sendmail_form()
        
        count = 0
        if f.validates():
            d = f.d; d.sql_query =  web.input().sql_query
示例#46
0
文件: bot.py 项目: zgruza/openlibrary
 def text_box(self, k):
     if self.input[k]:
         v = web.htmlquote(self.input[k])
         return '<input type="text" name="%s" value="%s">' % (k, v)
     else:
         return '<input type="text" name="%s">' % k
示例#47
0
def xmlquote(dat):
    xml = xmldom.parseString(dat)
    ret = xml.toprettyxml(indent='  ', newl='\n')
    return web.htmlquote(ret).replace('\n', '<br/>')
示例#48
0
def search(author, name):
    book_fields = ('title_prefix', 'title');
    q = { 'type': '/type/edition', 'authors': author, 'title_prefix': None, 'title': None, 'isbn_10': None}
    found = list(query_iter(q))
    db_author = ''
    names = set([name])
    t = ''
    books = []
    for e in found:
        locs = set()
        for i in e['isbn_10'] or []:
            locs.update(search_query('isbn', i))
        if not locs:
            books.append((e['key'], (e['title_prefix'] or '') + e['title'], None, []))
            continue
        found = data_from_marc(locs, name)
        if len(found) != 1:
            locs = []
            for i in found.values():
                locs.append(i)
            books.append((e['key'], (e['title_prefix'] or '') + e['title'], None, locs))
            continue
        marc_author = found.keys()[0]
        locs = found.values()[0]
        names.update(marc_author[0:2])
        books.append((e['key'], (e['title_prefix'] or '') + e['title'], marc_author, locs))

    authors = []
    names2 = set()
    for n in names:
        if ', ' in n:
            continue
        i = n.rfind(' ')
        names2.add("%s, %s" % (n[i+1:], n[:i]))
    names.update(names2)

    for n in names:
        for a in author_search(n):
            authors.append(a)

    for a in authors:
        q = {
            'type': '/type/edition',
            'authors': a['key'],
            'title_prefix': None,
            'title': None,
            'isbn_10': None
        }
        a['editions'] = list(query_iter(q))

    author_map = {}

    for key, title, a, locs in books:
        t += '<tr><td><a href="http://openlibrary.org' + key + '">' + web.htmlquote(title) + '</a>'
        t += '<br>' + ', '.join('<a href="http://openlibrary.org/show-marc/%s">%s</a>' % (i, i) for i in locs) + '</td>'
#        t += '<td>' + web.htmlquote(`a[2]`) + '</td>'
        if a:
            if a[2] not in author_map:
                dates = {'birth_date': a[2][0], 'death_date': a[2][1], 'dates': a[2][2]}
                db_match = [db for db in authors if author_dates_match(dates, db)]
                author_map[a[2]] = db_match[0] if len(db_match) == 1 else None

            match = author_map[a[2]]
            if match:
                t += '<td><a href="http://openlibrary.org%s">%s-%s</a></td>' % (match['key'], match['birth_date'] or '', match['death_date'] or '')
            else:
                t += '<td>%s-%s (no match)</td>' % (dates['birth_date'] or '', dates['death_date'] or '')
        t += '</tr>\n'

    ret = ''
    if authors:
        ret += '<ul>'
        for a in authors:
            ret += '<li><a href="http://openlibrary.org%s">%s</a> (%s-%s) %d editions' % (a['key'], web.htmlquote(name), a['birth_date'] or '', a['death_date'] or '', len(a['editions']))
        ret += '</ul>'

    return ret + '<table>' + t + '</table>'