fossil_reader.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import sqlite3 as lite
  4. import sys
  5. import os
  6. from sh import du
  7. from PIL import Image
  8. import os
  9. import re
  10. directory = "/mnt/wave/fossils.kit.edu/"
  11. con = lite.connect('fossil.db')
  12. with con:
  13. cur = con.cursor()
  14. counter = 1
  15. for folder in sorted(os.listdir(directory)):
  16. if os.path.isfile( directory+folder+"/"+folder+".zip" ) == False:
  17. continue
  18. if os.path.isdir(directory+folder) == False:
  19. continue
  20. with open(directory+folder+'/'+folder+'.txt', 'r') as myfile:
  21. data=myfile.read().replace('\n', '')
  22. fsize = du(directory+folder+"/"+folder+".zip")
  23. fsize = fsize.stdout.split("\t")[0].strip()
  24. # path joining version for other paths
  25. left_dir = directory+folder+"/left/left0000.png"
  26. top_dir = directory+folder+"/top/top0000.png"
  27. front_dir = directory+folder+"/front/front0001.png"
  28. imLeft=Image.open(left_dir)
  29. left_width = imLeft.size[0] # (width,height) tuple
  30. imTop=Image.open(top_dir)
  31. top_width = imTop.size[0] # (width,height) tuple
  32. imFront=Image.open(front_dir)
  33. front_width = imFront.size[0] # (width,height) tuple
  34. # path joining version for other paths
  35. left_dir = directory+folder+"/left/"
  36. top_dir = directory+folder+"/top/"
  37. front_dir = directory+folder+"/front/"
  38. total_left = len([name for name in os.listdir(left_dir) if (os.path.join(left_dir, name)).endswith('.png')])
  39. total_top = len([name for name in os.listdir(top_dir) if (os.path.join(top_dir, name)).endswith('.png')])
  40. total_front = len([name for name in os.listdir(front_dir) if (os.path.join(front_dir, name)).endswith('.png')])
  41. #total_left = 0
  42. #total_top = 0
  43. #total_front = 0
  44. index = folder
  45. #index = re.findall(r'\d+', index)
  46. name = str(folder)
  47. desc = data
  48. size = fsize
  49. #print name, size, total_left
  50. cur.execute("INSERT INTO Fossil VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", (name, desc, size, total_left, total_top, total_front, counter, left_width, top_width, front_width))
  51. counter += 1
  52. """
  53. #CREATE TABLE
  54. con = lite.connect('fossil.db')
  55. with con:
  56. cur = con.cursor()
  57. cur.execute("CREATE TABLE Fossil(Id INT, Name TEXT, Description TEXT, Size INT, Left INT, Top INT, Front INT)")
  58. #cur.execute("INSERT INTO Cars VALUES(1,'Audi',52642)")
  59. #cur.execute("INSERT INTO Cars VALUES(2,'Mercedes',57127)")
  60. #cur.execute("INSERT INTO Cars VALUES(3,'Skoda',9000)")
  61. #cur.execute("INSERT INTO Cars VALUES(4,'Volvo',29000)")
  62. #cur.execute("INSERT INTO Cars VALUES(5,'Bentley',350000)")
  63. #cur.execute("INSERT INTO Cars VALUES(6,'Citroen',21000)")
  64. #cur.execute("INSERT INTO Cars VALUES(7,'Hummer',41400)")
  65. #cur.execute("INSERT INTO Cars VALUES(8,'Volkswagen',21600)")
  66. """