12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import sqlite3 as lite
- import sys
- import os
- from sh import du
- directory = "/home/ntj/fossils_for_nicholas/"
- con = lite.connect('fossil.db')
- with con:
- cur = con.cursor()
- for folder in os.listdir(directory):
- with open(directory+folder+'/'+folder+'.txt', 'r') as myfile:
- data=myfile.read().replace('\n', '')
- fsize = du(directory+folder+"/"+folder+".zip")
- fsize = fsize.stdout.split("\t")[0].strip()
- # path joining version for other paths
- left_dir = directory+folder+"/left"
- top_dir = directory+folder+"/top"
- front_dir = directory+folder+"/front"
- total_left = len([name for name in os.listdir(left_dir) if (os.path.join(left_dir, name)).endswith('.tif')])
- total_top = len([name for name in os.listdir(top_dir) if (os.path.join(top_dir, name)).endswith('.tif')])
- total_front = len([name for name in os.listdir(front_dir) if (os.path.join(front_dir, name)).endswith('.tif')])
- index = int(folder[-5:])
- name = str(folder)
- desc = data
- size = fsize
- #print name, size, total_left
- cur.execute("INSERT INTO Fossil VALUES (?, ?, ?, ?, ?, ?, ?);", (index, name, desc, size, total_left, total_top, total_front))
- """
- #CREATE TABLE
- con = lite.connect('fossil.db')
- with con:
- cur = con.cursor()
- cur.execute("CREATE TABLE Fossil(Id INT, Name TEXT, Description TEXT, Size INT, Left INT, Top INT, Front INT)")
- #cur.execute("INSERT INTO Cars VALUES(1,'Audi',52642)")
- #cur.execute("INSERT INTO Cars VALUES(2,'Mercedes',57127)")
- #cur.execute("INSERT INTO Cars VALUES(3,'Skoda',9000)")
- #cur.execute("INSERT INTO Cars VALUES(4,'Volvo',29000)")
- #cur.execute("INSERT INTO Cars VALUES(5,'Bentley',350000)")
- #cur.execute("INSERT INTO Cars VALUES(6,'Citroen',21000)")
- #cur.execute("INSERT INTO Cars VALUES(7,'Hummer',41400)")
- #cur.execute("INSERT INTO Cars VALUES(8,'Volkswagen',21600)")
- """
|