|
@@ -1,8 +1,10 @@
|
|
|
-#coding=utf-8
|
|
|
+#!/usr/bin/python
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
import os
|
|
|
import io
|
|
|
from PIL import Image
|
|
|
from HTMLParser import HTMLParser
|
|
|
+import sqlite3 as lite
|
|
|
import tornado.httpserver
|
|
|
import tornado.ioloop
|
|
|
import tornado.options
|
|
@@ -27,7 +29,8 @@ class MyHTMLParser(HTMLParser):
|
|
|
self.ttype = "p"
|
|
|
|
|
|
def handle_data(self, data):
|
|
|
- self.fed.append({"type": self.ttype, "text": data.strip()})
|
|
|
+ self.fed.append({"type": self.ttype,
|
|
|
+ "text": data.strip()})
|
|
|
|
|
|
def get_data(self):
|
|
|
return self.fed
|
|
@@ -49,11 +52,29 @@ class Application(tornado.web.Application):
|
|
|
|
|
|
|
|
|
class MainHandler(tornado.web.RequestHandler):
|
|
|
+
|
|
|
+ #def __init__(self):
|
|
|
+ # con = lite.connect('fossil.db')
|
|
|
+ #with con:
|
|
|
+ # cur = con.cursor()
|
|
|
|
|
|
def get(self):
|
|
|
|
|
|
+ con = lite.connect('fossil.db')
|
|
|
+ with con:
|
|
|
+ cur = con.cursor()
|
|
|
+ cur.execute("SELECT * FROM Fossil ORDER BY id")
|
|
|
+ data = cur.fetchall()
|
|
|
+
|
|
|
+ data_list = [ [x[0], x[1]] for x in data]
|
|
|
+
|
|
|
+ current_index = 0
|
|
|
parser = MyHTMLParser()
|
|
|
- parser.feed("<i>Xenomorphia resurrecta</i>, male; well-preserved, head hollow")
|
|
|
+ print data[current_index][2]
|
|
|
+ parser.feed(data[current_index][2])
|
|
|
+ desc = parser.get_data()
|
|
|
+
|
|
|
+ data_size = ("%.2f" % (data[current_index][3] / 1000000.0))
|
|
|
|
|
|
self.render(
|
|
|
"index.html",
|
|
@@ -69,39 +90,43 @@ class MainHandler(tornado.web.RequestHandler):
|
|
|
Institute of Crop Science and Resource Conservation, University of Bonn, Bonn, Germany;
|
|
|
Laboratory for Applications of Synchrotron Radiation, Karlsruhe Institute of Technology,
|
|
|
Karlsruhe, Germany""",
|
|
|
- data_list = [
|
|
|
- "NRM-PZ_Ar65716",
|
|
|
- "Saab",
|
|
|
- "Mercedes",
|
|
|
- "Audi"],
|
|
|
- desc = parser.get_data(),
|
|
|
- data_size = "1.3 GB"
|
|
|
+ data_list = data_list,
|
|
|
+ desc = desc,
|
|
|
+ data_size = data_size
|
|
|
)
|
|
|
|
|
|
|
|
|
class GenFileStreamerHandler(tornado.web.RequestHandler):
|
|
|
CHUNK_SIZE = 512000
|
|
|
-
|
|
|
+ DATA_PATH = "/home/ntj/fossils_for_nicholas"
|
|
|
+
|
|
|
@tornado.web.asynchronous
|
|
|
@tornado.gen.engine
|
|
|
def get(self):
|
|
|
- #print self.get_arguments("did")
|
|
|
- self.path = PATH + '/data/01_NRM-PZ_Ar65716/test.zip'
|
|
|
- file_name = "01_NRM-PZ_Ar65716.zip"
|
|
|
- self.set_header('Content-Type',
|
|
|
- 'application/octet-stream')
|
|
|
- self.set_header('Content-Disposition',
|
|
|
- 'attachment; filename=' + file_name)
|
|
|
- self.set_header("Content-Length",
|
|
|
- os.path.getsize(self.path))
|
|
|
- self.flush()
|
|
|
- fd = open(self.path, "rb")
|
|
|
- data = fd.read(self.CHUNK_SIZE)
|
|
|
- while data:
|
|
|
- self.write(data)
|
|
|
- yield tornado.gen.Task(self.flush)
|
|
|
+ cdid = self.get_arguments("did")
|
|
|
+ con = lite.connect('fossil.db')
|
|
|
+ with con:
|
|
|
+ cur = con.cursor()
|
|
|
+ cur.execute("SELECT name FROM Fossil WHERE name = ?", (cdid))
|
|
|
+ data_key = cur.fetchall()
|
|
|
+
|
|
|
+ if len(data_key) > 0:
|
|
|
+ file_name = str(cdid[0]) + ".zip"
|
|
|
+ self.path = self.DATA_PATH + str(cdid[0]) + "/" + file_name
|
|
|
+ self.set_header('Content-Type',
|
|
|
+ 'application/octet-stream')
|
|
|
+ self.set_header('Content-Disposition',
|
|
|
+ 'attachment; filename=' + file_name)
|
|
|
+ self.set_header("Content-Length",
|
|
|
+ os.path.getsize(self.path))
|
|
|
+ self.flush()
|
|
|
+ fd = open(self.path, "rb")
|
|
|
data = fd.read(self.CHUNK_SIZE)
|
|
|
- fd.close()
|
|
|
+ while data:
|
|
|
+ self.write(data)
|
|
|
+ yield tornado.gen.Task(self.flush)
|
|
|
+ data = fd.read(self.CHUNK_SIZE)
|
|
|
+ fd.close()
|
|
|
self.finish()
|
|
|
|
|
|
|