def handle_get(): link_id = request.path_info() try: link_id = int(link_id[1:]) except ValueError: raise response.NotFound(link_id) except TypeError: raise response.NotFound("") text_data = db.get_text_data(link_id) screenshots = db.get_screenshots(link_id) link = db.get_link(link_id) link_date = link["linked_on"].strftime("%Y-%m-%s %H:%M:%S") write_html_lead("Link Information for %s" % text_data[-1]["title"], sys.stdout, meta=[ {"name": "viewport", "content": "width=device-width"}, {"charset": "UTF-8"}], links=[ {"rel": "stylesheet", "type": "text/css", "href": css_path}]) sys.stdout.write("<body>") sys.stdout.write("<h1>%s</h1>" % html_escape(link["url"])) sys.stdout.write("<p>Added at %s" % html_escape(link_date)) sys.stdout.write("<h1>%i text captures for this page</h1>" % len(text_data))
def handle_get(): links = db.get_link_list() css_path = os.path.join(static_path, "list.css") write_html_lead("Bookmarks", sys.stdout, links=[ {"rel": "stylesheet", "type": "text/css", "href": css_path}], meta=[ {"name": "viewport", "content": "width=device-width"}, {"charset": "UTF-8"}]) sys.stdout.write("<body>") sys.stdout.write("<table><thead><tr><th>Date<th>Link<th>Info<tbody>") row_template = """<tr> <td>%s <td><a href='%s'>%s</a> <td><a href='%s'>%s</a>""" for link in links: display = html_escape(link[1] or link[2]) if link[3]: name = os.path.basename(link[3]) path = os.path.join(static_path, "thumbnails", name) img = "<img src='%s' alt='%s'>" % (html_escape(path), display) else: img = "No thumbnail" date = html_escape(link[4].strftime("%y-%m-%d %H:%M")) url = html_escape(link[2]) row = row_template % (date, url, display, "link.py?link_id=%s" % url_encode(str(link[0])), img) sys.stdout.write(row) path = db.get_thumbnail(link[0]) sys.stdout.write("</table></body></html>")