예제 #1
0
class FileHandler(object):

    """
    This class takes care of appending chunks to the specified file that
    is being uploaded. When the upload is complete, the file is then moved
    to its specified path.
    """

    def __init__(self, body):
        """
        Constructor that needs a file path
        """
        self.body = body
        self.db = DBHandler(current_app.config["DBFILE"])
        self.cursor = self.db.getCursor()

    def write_chunk(self):
        """
        Find the file hash in SQLite, append the chunk to the returned file.
        Each chunk will be checksummed to ensure file/data integrity.
        """
        pass

    def create_file_metadata(self):
        """
        Create the file metadata.
        """
        if all(k in self.body for k in ('name', 'path', 'size', 'hash')):
            c = self.db.getCursor()
            if self.db.exists("file", "hash", self.body['hash']):
                return Response(
                    'File exists\n',
                    status=200, mimetype='text/plain')
            else:
                try:
                    sql = """
                        INSERT INTO file(name, path, size, file_hash)
                        VALUES('{name}','{path}', {size}, '{hash}')
                        """.format(
                        name = self.body['name'],
                        path = self.body['path'],
                        hash = self.body['hash'],
                        size = self.body['size'])
                    print sql
                    c.execute(sql)
                    self.db.commit()
                except Exception, e:
                    errormsg = \
                        u"Unsuccessful database insert transaction:" \
                        + str(e)
                    print errormsg
                    #log.exception(errormsg, self.__class__.__name__)
                    return Response(
                        'Unsuccessful database insert transaction\n',
                        status=500, mimetype='text/plain')
            return Response('', status=201, mimetype='text/plain')
        return Response(
            'Missing data in JSON\n',
            status=500, mimetype='text/plain')
예제 #2
0
 def countWords(self, dbName):
     query = "Select * from wort order by count desc"
     dbh = DBHandler()
     dbh.reconnect(dbName)
     cursor = dbh.execute(query)
     dbh.commit()
     if cursor == None: print "No cursor returned: ", cursor
     return [[entry[1], entry[2]] for entry in cursor.fetchall()]
예제 #3
0
import sqlite3
from cetizen import PnoCrawler, ReleasePriceCrawler, UsedPriceCrawler
from dbhandler import DBHandler

if __name__ == '__main__':

    # DB 연결
    conn = sqlite3.connect('cetizen.db')
    db = DBHandler(conn)

    db.delTableAll('상품정보')
    db.delTableAll('출고가정보')
    db.delTableAll('중고가정보')
    db.commit()

    # 상품정보 수집
    pno_crawler = PnoCrawler()
    df = pno_crawler.crawling()
    db.insTable('상품정보', df)

    # 상품코드 목록 추출
    pno = list(db.getTableAll('상품정보')['PNO'])

    # 출고가정보 수집
    release_price_crawler = ReleasePriceCrawler(pno[:3])
    df = release_price_crawler.crawling()
    db.insTable('출고가정보', df)

    # 중고가정보 수집
    used_price_crawler = UsedPriceCrawler(pno[:3])
    df = used_price_crawler.crawling()