コード例 #1
0
def test_list_books():
    books = bookdb.BookDB()
    titles = books.titles()
    assert len(titles) > 1
    print titles
    for title in titles:
        assert 'title' in title
        assert 'id' in title
コード例 #2
0
def ind_book_info(id):
    books = bookdb.BookDB()
    bookdic = books.title_info(id)
    bktitle = bookdic['title']
    bkisbn = bookdic['isbn']
    bkpublisher = bookdic['publisher']
    bkauthor = bookdic['author']
    infoaboutbook = '<P> Tittle: %s</P><P> ISBN: %s</P><P> Publisher: %s</P><P> Author: %s</P>' % (bktitle, bkisbn, bkpublisher, bkauthor) 
    return infoaboutbook
コード例 #3
0
def book_details(bookID):
    books = bookdb.BookDB()

    details = books.title_info(bookID)
    hold = []
    for key, value in details.items():
        hold.append(key + ": " + value)
    page = message_template2 % '<br>'.join(hold)
    return page
コード例 #4
0
def book_info():
    books = bookdb.BookDB()
    titles = books.titles()
    numbooks = len(titles)
    counter = 0
    while counter < numbooks:
        id = titles[counter]['id']
        print id
        info = books.title_info(id)
        print info
        counter += 1
コード例 #5
0
def test_get_book_info():
    books = bookdb.BookDB()
    titles = books.titles()
    id = titles[0]['id']
    print id
    info = books.title_info(id)
    print info
    assert 'title' in info
    assert info['title'] == titles[0]['title']
    assert 'publisher' in info
    assert 'isbn' in info
    assert 'author' in info
コード例 #6
0
def mk_index():
    books = bookdb.BookDB()
    titles = books.titles()
    numbooks = len(titles)
    counter = 0
    bksindexpage = ''
    while counter < numbooks:
        id = titles[counter]['id']
        title = titles[counter]['title']
        #print id
        #print title
        bksindexpage = bksindexpage + '<p><a href="http://localhost:8080/getbook?%s"> %s </a></p>' % (id, title)
        counter += 1
    return bksindexpage
コード例 #7
0
def book_titles():
    books = bookdb.BookDB()
    titles = books.titles()
    #assert len(titles) > 1
    #print titles
    messages = ""
    for title in titles:
        x = title["title"]
        y = title["id"]
        link = '<a href= ' + '"/' + y + '"' + '>%s</a><br>'
        messages = (link % x) + messages
        #messages = ('<a href=%s>%s</a><br>' %x) + messages # insert at head

        page = message_template2 % messages
    return page  # li
コード例 #8
0
ファイル: book_pages.py プロジェクト: jenny-liang/uw_python
<head>
<title>%s</title>
</head>
<body>
%s
</body>
</html>
"""

# No need for message page
# Flask converts view function return string to HTML page

app = Flask(__name__)

app.debug = True # development only - remove on production machines
bookDb = bookdb.BookDB()
# View functions generate HTTP responses including HTML pages and headers

@app.route('/book_pages.py') #decorate another view function.
def message_page():
    # Flask Quickstart suggests request.form should work, but here it is empty
    # Flask converts return string to HTML page
    #return 'Message: %s' % request.args['message']  # args is a dictionary. 'message' is the key.
    bookTitle = []
    bookTitleLines = ''
    for titleDict in bookDb.titles():
        title = titleDict['title']
        bookTitle.append(title)
    for b in bookTitle:
        bookTitleLines = bookTitleLines + "<a href='%s'>%s</a>" %(b, b) + "\n<br>"
    return bookTitleLines
コード例 #9
0
ファイル: 30minWS.py プロジェクト: RhanTeg0th/Echo
                return (301, uri + '/')
        else:
            return (404, uri)
    except IOError, e:
        return (404, e)


def get_mime(uri):
    return mime_types.get(os.path.splitext(uri)[1], 'text/plain')


def send_response(stream, content):
    stream.write(response[content[0]] % content[1:])


if __name__ == '__main__':
    B = bookdb.BookDB(database, linklist)
    args, nargs = sys.argv[1:], len(sys.argv) - 1
    host, port = (args + defaults[-2 + nargs:])[0:2]
    server = server_socket(host, port)

    print 'starting %s on %s...' % (host, port)
    try:
        while True:
            stream = listen(server)
            send_response(stream, get_content(get_request(stream), B))
            stream.close()
    except KeyboardInterrupt:
        print 'shutting down...'
    server.close()