Archive for the ‘python’ category

ImageCloud funtioning again

September 9, 2006

I spent a little bit of time hacking at ImageCloud after math class. The code is working again, but it’s ugly on Windows. The Strings that have the filenames do \\ on windows. I think this is because it needs to escape the slash, but it is still ugly. I knew I should have ignored Windows… 😉

 #!/usr/bin/env python
 # -*- coding: iso-8859-1 -*-

 # Program : ImageCloud - A Python Photo TaggerDB
 # Author  : Kristofer White
 # E-Mail  : kristoferwhite@gmail.com


 ## Import Modules And Such ##
 import os, sys, glob, pickle

 class iCloud(object):

 	def prompt(self, tagDB):
 		print "Do you want to [B]rowse for, [A]dd images, or [Q]uit?"
 		ans = raw_input("[B/A/Q] ?")
 		if ans.lower() == "b":
 			Browse.dbQuery(Browse())
 		elif ans.lower() == "a":
 			Add()
 		elif ans.lower() == "q":
 			self.dbPickle(tagDB)
 			sys.exit(0)
 		else:
 			print "Unrecognized response! Try again"
 			self.prompt(tagDB)
 	def dbPickle(self, tagDB):
 		# it is possible to do:
 		# tagDB = pickle.dump(tagDB, os.path.expanduser("~/.imagecloudDB"))
 		fout = open(os.path.expanduser("~/.imagecloudDB"), "w")
 		pickle.dump(tagDB, fout)
 		fout.close()
 	def dbUnPickle(self):
 		# it is possible to do:
 		# tagDB = pickle.load(os.path.expanduser("~/.imagecloudDB"))
 		fin = open(os.path.expanduser("~/.imagecloudDB"), "r")
 		tagDB = pickle.load(fin)
 		fin.close()
 		return tagDB



 class Browse(object):

 	def dbQuery(self):
 		""" Search Gallery for Tag """
 		tagDB = iCloud.dbUnPickle(iCloud())
 		tag = raw_input("That is the tag that you wish to search for? > ")
 		if tag in tagDB:
 			print tagDB[tag].split("||")
 			iCloud.prompt(iCloud(), tagDB)
 		else:
 			print "Sorry, tag not found!"
 			self.dbQuery()
 	def tagCloudGen(self):
 		""" Generate the Tag Cloud """



 class Add(object):

 	def __init__(self):
 		""" Ask for image dir """
 		path = raw_input("Path ?")
 		self.folderAdd(os.path.abspath(os.path.expanduser(path)))
 	def folderAdd(self, path):
 		""" Add folder passed via path """
 		filelist = glob.glob("%s/*.[Jj][Pp][Gg]" % path)
 		filelist.extend(glob.glob("%s/*.[Pp][Nn][Gg]" % path))
 		filelist.extend(glob.glob("%s/*.[Gg][Ii][Ff]" % path))
 		self.tagger(filelist)
 	def tagger(self, filelist):
 		""" Tag files from filelist and pickle """
 		tagDB = iCloud.dbUnPickle(iCloud())
 		print "Seperate tags by spaces!"
 		for filename in filelist:
 			taglist = raw_input("Tags for %s ?n" % filename).split()
 			for tag in taglist:
 				if tag in tagDB:
 					tagDB[tag] = "%s||%s" % (tagDB[tag], os.path.abspath(filename))
 				else:
 					tagDB[tag] = os.path.abspath(filename)
 		iCloud.dbPickle(iCloud(), tagDB)
 		print tagDB
 		iCloud.prompt(iCloud(), tagDB)


 if __name__ == "__main__":

 	try:
 		fin = open(os.path.expanduser("~/.imagecloudDB"), "r")
 		tagDB = pickle.load(fin)
 		fin.close()
 	except IOError:
 		tagDB = {}
 		iCloud.dbPickle(iCloud(), tagDB)
 	c= iCloud()
 	c.prompt(tagDB)

technorati tags:, , ,

ImageCloud found! Sort of…

September 8, 2006

I was searching through one of the paste-bin sites out there (http://rafb.net/paste or deadbeefbabe) and found part of ImageCloud. The only problem, it’s not a big part. It still saves me about half an hour though. Yeah, I know, I should be sleeping for math class, but I’m not tired for some reason. As always, what ever code you find here is subject to GPL restrictions. Do what you want with it. Use it, hack it, however, if the code causes you problems, I am NOT responsible in any way shape or form. 🙂

#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-  

# Program : ImageCloud - A Python Photo TaggerDB
# Author  : Kristofer White
# E-Mail  : kristoferwhite@gmail.com  

## Import Modules And Such ##
import os, sys, glob, pickle  

class iCloud(object):
    def __init__(self):
        print "Do you want to [B]rowse for, [A]dd images, or [Q]uit?"
        ans = raw_input("[B/A/Q] ?")
        if ans.lower() == "b":
            Browse.dbQuery(Browse(), tagDictDB, dbPath)
        elif ans.lower() == "a":
            Add()
        elif ans.lower() == "q":
            self.dbPickle(tagDictDB, dbPath)
            sys.exit(0)
        else:
            print "Unrecognized response! Try again"
    def dbPickle(self, tagDB):
        fout = open(os.path.expanduser("~/.imagecloudDB"), "w")
        pickle.dump(tagDB, fout)
        fout.close()
    def dbUnPickle(self):
        fin = open(os.path.expanduser("~/.imagecloudDB"), "r")
        tagDB = pickle.load(fin)
        fin.close()
        return tagDB  

class Browse(object):
    def dbQuery(self, tagDictDB, dbPath):
        """ Search Gallery for Tag """)
    def tagCloudGen(self):
        """ Generate the Tag Cloud """  

class Add(object):
    def __init__(self):
        """ Ask for image dir """
        path = raw_input("Path ?")
        self.folderAdd(path)
    def folderAdd(self, path):
        """ Add folder passed via path """
        print path
	def tagger(self, list):
		""" Tag files from path and pickle """  

c = iCloud()