]> git.zarvox.org Git - wp3.git/commitdiff
Merge photos from a folder with files of the form <netid>.jpg
authorDrew Fisher <drew.m.fisher@gmail.com>
Sat, 22 Aug 2009 05:35:33 +0000 (00:35 -0500)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sat, 22 Aug 2009 05:35:33 +0000 (00:35 -0500)
We support <netid>.jpg and <netid>.JPG, at the moment.  Additional
extensions should be easy enough to provide.  Additional (read:
time-based) merge techniques are still to come.

mergephotos.py

index f9d319816e7628979d944aaf39f72acfb6c76b2b..acd26b68fe688ae30a6243dc4c8d26f5b0cdef98 100644 (file)
@@ -12,5 +12,33 @@ class MergePhotos(QWidget):
                self.setLayout(self.layout)
 
        def beginMerge(self):
-               print QFileDialog.getExistingDirectory( None, "Pick folder of photos", ".")
+               foldertext = QFileDialog.getExistingDirectory( None, "Pick folder of photos", ".")
+               if not foldertext.isEmpty():
+                       print foldertext
+                       dir = QDir(foldertext)
+                       #dir.setNameFilters(["*.jpg", "*.JPG"])
+                       q = QSqlQuery(self.db)
+                       q.exec_("SELECT id, netid FROM people WHERE photo IS NULL")
+                       rec = q.record()
+                       col_id = rec.indexOf("id")
+                       col_netid = rec.indexOf("netid")
+                       while q.next():
+                               # if netid.jpg exists, load it, write it to a QByteArray, bind it, and update that row
+                               fileName = q.value(col_netid).toString() + QString(".jpg")
+                               if not dir.exists(fileName):
+                                       fileName = q.value(col_netid).toString() + QString(".JPG")
+                               if dir.exists(fileName):
+                                       image = QImage()
+                                       image.load(dir.absoluteFilePath(fileName))
+                                       ba = QByteArray()
+                                       buffer = QBuffer(ba)
+                                       buffer.open(QIODevice.WriteOnly)
+                                       image.save(buffer, "JPG")
+                                       buffer.close()
+                                       update_q = QSqlQuery(self.db)
+                                       update_q.prepare("UPDATE people SET photo=:photo WHERE id=:id")
+                                       update_q.bindValue(":photo", QVariant(ba))
+                                       update_q.bindValue(":id", q.value(col_id))
+                                       update_q.exec_()
+                                       print "Auto-imported photo for",q.value(col_netid).toString()