import sqlite3
conn = sqlite3.connect('example.db')

c = conn.cursor()


import os
import hashlib
import time

def get_file_md5(filePath):
	h = hashlib.md5()
	h.update(open(filePath,"rb").read())
	return h.hexdigest()

def get_file_sha256(filePath):
	h = hashlib.sha256()
	h.update(open(filePath,"rb").read())
	return h.hexdigest()


def get_dir_data(dir_path):
	dir_path = os.path.realpath(dir_path)
	
	#print next(os.walk(dir_path))[2]
	#print os.path.basename(dir_path)
	
	id_location = 0
	id_file = 0
	for dir_file in next(os.walk(dir_path))[2]:
		file_name = dir_file
		file_md5 = get_file_md5(dir_file)
		file_sha256 = get_file_sha256(dir_file)
		file_size = os.path.getsize(dir_file)
		
		file_time = time.gmtime(os.path.getctime(dir_file))
		file_formatted_time = time.strftime("%Y-%m-%d %I:%M:%S %p", file_time)
		file_path = os.path.realpath(dir_file)
		

		location_values = (id_location, file_path)
		c.execute("INSERT INTO location VALUES (?, ?)", location_values)

		files_values = (id_location, id_file)
		c.execute("INSERT INTO files VALUES (?, ?)", files_values)

		file_info_values = (id_file, file_name, file_size, file_formatted_time, file_md5)
		c.execute("INSERT INTO file_info VALUES (?, ?, ?, ?, ?)", file_info_values)

		id_location += 1
		id_file += 1


get_dir_data('./')

# Save (commit) the changes
conn.commit()

conn.close()
[((2, 7, 2, 36), 'sqlite3.connect', 'sqlite3.connect', ({(2, 23, 2, 35): '"""example.db"""'}, {}), "('example.db')", False, 'import sqlite3\n'), ((12, 5, 12, 18), 'hashlib.md5', 'hashlib.md5', ({}, {}), '()', False, 'import hashlib\n'), ((17, 5, 17, 21), 'hashlib.sha256', 'hashlib.sha256', ({}, {}), '()', False, 'import hashlib\n'), ((23, 12, 23, 38), 'os.path.realpath', 'os.path.realpath', ({(23, 29, 23, 37): 'dir_path'}, {}), '(dir_path)', False, 'import os\n'), ((34, 14, 34, 39), 'os.path.getsize', 'os.path.getsize', ({(34, 30, 34, 38): 'dir_file'}, {}), '(dir_file)', False, 'import os\n'), ((37, 24, 37, 72), 'time.strftime', 'time.strftime', ({(37, 38, 37, 60): '"""%Y-%m-%d %I:%M:%S %p"""', (37, 62, 37, 71): 'file_time'}, {}), "('%Y-%m-%d %I:%M:%S %p', file_time)", False, 'import time\n'), ((38, 14, 38, 40), 'os.path.realpath', 'os.path.realpath', ({(38, 31, 38, 39): 'dir_file'}, {}), '(dir_file)', False, 'import os\n'), ((30, 22, 30, 39), 'os.walk', 'os.walk', ({(30, 30, 30, 38): 'dir_path'}, {}), '(dir_path)', False, 'import os\n'), ((36, 26, 36, 52), 'os.path.getctime', 'os.path.getctime', ({(36, 43, 36, 51): 'dir_file'}, {}), '(dir_file)', False, 'import os\n')]