class GaAddItem: path = None conn = None cur = None gal = None log = None def initpath(self, pa = '/directory of images/'): self.path = pa self.log = open('./log/log.' + str(datetime.date.today()), 'a') print >> self.log, '============================= ', datetime.date.today(), ' ============================' def initdb(self, host = 'localhost', user = '******', passwd = 'xxxx', db = 'beauty', port = 3306, charset = 'utf8'): self.conn = MySQLConnection.MySQLConn() self.conn.connect(m_host = host, m_user = user, m_passwd = passwd, m_db = db) self.cur = self.conn.cursor() self.gal = Gallery('http://localhost/gallery2', 2) self.gal.login('xxxx','xxxx') def add(self): album = self.gal.fetch_albums()['7'] self.cur.execute("""select url from adds"""); results = self.cur.fetchall() items = [] today = str(datetime.date.today()) cnt = 0 for url in results: hs = hashlib.sha1() hs.update(url[0]) imagename = self.path + hs.hexdigest() + '.jpg' if os.path.isfile(imagename): cnt = cnt + 1 self.gal.add_item(album['name'], imagename, today+'-'+str(cnt), 'show_'+str(cnt)) items.append(url[0]) else: print >> self.log, imagename, ' not founded!' self.cur.executemany('insert into url (url) values (%s)', items) self.conn.commit() def close(self): self.cur.close() self.conn.close() self.log.close()
import simplejson from galleryremote import Gallery import sys import os import urllib galleryurl = sys.argv[1] outputdir = sys.argv[2] print galleryurl g = Gallery(galleryurl, 2) albums = g.fetch_albums() os.mkdir(outputdir) open(outputdir + "/albums.info", "w").write(simplejson.dumps(albums, indent=4)) for (album, albuminfo) in albums.items(): print " *** Processing album %s\n" % album images = g.fetch_album_images(album) albumpath = "%s/%s" % (outputdir, album) os.mkdir(albumpath) open("%s/images.info" % albumpath, "w").write(simplejson.dumps(images, indent=4)) for image in images: print "Downloading image " + image['name'] urllib.urlretrieve(galleryurl + "/main.php?g2_view=core%3ADownloadItem&g2_itemId=" + image['name'], albumpath + "/" + image['name'] + ".data")
if opts.debug: logging_level = logging.DEBUG else: logging_level = logging.INFO console_handler = logging.StreamHandler() formatter = logging.Formatter("%(asctime)s:%(levelname)8s:%(message)s") console_handler.setFormatter(formatter) logger.addHandler(console_handler) logger.setLevel(logging_level) if conf.getboolean("gallery2", "enabled"): logger.debug("Logging into gallery") g = Gallery(conf.get("gallery2", "url")) g.login(conf.get("gallery2", "user"), conf.get("gallery2", "password")) logger.debug("Finding our album") albums = g.fetch_albums_prune() our_album = conf.get("gallery2", "albumname").lower() candidate_albums = [k for k, v in albums.iteritems() if v["title"].lower() == our_album] if not candidate_albums: logger.critical("Couldn't find a %s album!", our_album) sys.exit(1) album_name = candidate_albums[0] if args: to_work = args
def initdb(self, host = 'localhost', user = '******', passwd = 'xxxx', db = 'beauty', port = 3306, charset = 'utf8'): self.conn = MySQLConnection.MySQLConn() self.conn.connect(m_host = host, m_user = user, m_passwd = passwd, m_db = db) self.cur = self.conn.cursor() self.gal = Gallery('http://localhost/gallery2', 2) self.gal.login('xxxx','xxxx')