Exemple #1
0
def smugup(opts, args):
    albumId = opts.album
    if "_" in albumId:
        albumId, albumKey = albumId.split("_")
    logger.info("using album %s", albumId)

    # login
    m = pysmug.login()

    filenames = set()
    if not opts.overwrite:
        # get the current filenames
        images = m.images_get(albumId=albumId, albumKey=albumKey, heavy=True)
        [filenames.add(x["FileName"]) for x in images["Album"]["Images"]]

    # check for files to upload
    n = 0
    b = m.batch()
    b.concurrent = 2
    for arg in args:
        basename = os.path.basename(arg)
        if basename in filenames:
            logger.warning("skipping %s", arg)
            continue
        n += 1
        logger.info("uploading %s", arg)
        b.images_upload(albumId=albumId, filename=arg)

    # upload
    logger.info("uploading %d files", n)
    for i, (params, result) in enumerate(b()):
        logger.info("uploaded (%d/%d) %s", i, n, result)
Exemple #2
0
def smugup(opts, args):
    albumId = opts.album
    if "_" in albumId:
        albumId, albumKey = albumId.split("_")
    logger.info("using album %s", albumId)

    # login
    m = pysmug.login()

    filenames = set()
    if not opts.overwrite:
        # get the current filenames
        images = m.images_get(albumId=albumId, albumKey=albumKey, heavy=True)
        [filenames.add(x["FileName"]) for x in images["Album"]["Images"]]

    # check for files to upload
    n = 0
    b = m.batch()
    b.concurrent = 2
    for arg in args:
        basename = os.path.basename(arg)
        if basename in filenames:
            logger.warning("skipping %s", arg)
            continue
        n += 1
        logger.info("uploading %s", arg)
        b.images_upload(albumId=albumId, filename=arg)

    # upload
    logger.info("uploading %d files", n)
    for i, (params, result) in enumerate(b()):
        logger.info("uploaded (%d/%d) %s", i, n, result)
Exemple #3
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    p = OptionParser(usage="usage: %prog [options] AlbumID AlbumKey\n       %prog [options] AlbumID_AlbumKey\n  (second usage is handy for copy/paste from a SmugMug URL).\n  Username and password are stored in ~/.pysmug.")
    p.add_option("-q", "--quiet", dest="quiet",
        default=False, action="store_true", help="Don't display names of images downloaded.")
    opts, args = p.parse_args()
    
    if len(args) == 1 and args[0].find("_"):
        idandkey = args[0].split("_")
        albumid = idandkey[0]
        albumkey = idandkey[1]
    elif len(args) == 2:
        albumid = args[0]
        albumkey = args[1]
    elif len(args) < 1 or len(args) > 2 or opts.help == True:
        Usage(p)
        return(-1)

    m = pysmug.login()
    b = m.batch()
    if (opts.quiet == False):
        print "Downloading..."
    total_images = 0
    for album, image in b.images_download(AlbumID=albumid, AlbumKey=albumkey):
        if (opts.quiet == False):
            targetfilename = image['Image']['FileName'].split("/")[-1]
            print targetfilename + ": " + image['stat']
        total_images += 1
        
    if (opts.quiet == False):
        print "Total images: " + str(total_images)
        
    return 0;
Exemple #4
0
 def __init__(self):
     self.m = pysmug.login()
     self.fields = dict(_fields)
Exemple #5
0
 def __init__(self):
     self.m = pysmug.login()
     self.fields = dict(_fields)
Exemple #6
0
 def setup_class(cls):
     cls.m = pysmug.login()