Ejemplo n.º 1
0
def album_uploader(path):
    data = parse_meta(os.path.join(path, 'meta'))
    if data['type'] != "album":
        print("ALARM! UVAGA! meta contains wrong information! %s" % path)
        data['type'] = "album"
    if data['dir'] in UPLOADED:
        print("Album %s is already uploaded" % data['dir'])
        return UPLOADED[data['dir']]
    photos = []

    # At first we have to download photos from that album
    # and after create photoset for that photos
    for photo in filter(lambda x: not x.endswith('meta') and x != "log",
                        os.listdir(path)):
        photo_path = os.path.join(path, photo)
        photo_id = photo_uploader(photo_path)
        photos.append(photo_id)

    photoset_id = flickr.photosets_create(
        title=data['title'], description=data['description'],
        primary_photo_id=photos[0]).getchildren()[0].attrib['id']
    update_log(data['dir'], photoset_id)
    my_log('album:::%s:::%s' % (data['title'], photoset_id))

    # we already added first photo into the photoset and add another n-1
    for photo_id in photos[1:]:
        try:
            flickr.photosets_addPhoto(photoset_id=photoset_id, photo_id=photo_id)
        except FlickrError, e:
            print e
Ejemplo n.º 2
0
 def write_file(self):
     link = self.attributes['image']
     path = self.attributes['path']
     if not os.path.isfile(path):
         with open(path, 'w') as fd:
             fd.write(urllib2.urlopen(link).read())
     with open(path + ".meta", "w") as meta:
         meta.write(self.get_meta())
         my_log("File %s is writted" % path)
Ejemplo n.º 3
0
def photo_uploader(path):
    data = parse_meta(path+'.meta')
    if data['path'] in UPLOADED:
        print("Item %s is already uploaded" % data['path'])
        return UPLOADED[data['path']]

    photo_id = flickr.upload(filename=data['path'], title=data['title'],
                             description=data['description']).find('photoid').text
    update_log(data['path'], photo_id)
    my_log('photo:::%s:::%s' % (data['title'], photo_id))
    dl = data['date'].split('/')
    date = "%s-%s-%s" % (dl[2], dl[0], dl[1])
    flickr.photos_setDates(photo_id=photo_id, date_posted=date)
    return photo_id
Ejemplo n.º 4
0
def collection_uploader(path):
    data = parse_meta(os.path.join(path, 'meta'))
    if data['dir'] in UPLOADED:
        print("Collection %s is already uploaded")
        return UPLOADED[data['dir']]

    inners = []
    isdir = is_dir(path)
    for inner in filter(isdir, os.listdir(path)):
        inner_path = os.path.join(path, inner)
        inner_id = uploader(inner_path)
        inners.append(inner_id)

    collection_id = flickr.collections_create(title=data['title'],
                                              description=data['description']
                                              ).getchildren()[0].attrib['id']
    update_log(data['dir'], collection_id)
    my_log('collection:::%s:::%s' % (data['title'], collection_id))

    flickr.collections_editSets(collection_id=collection_id,
                                photoset_ids=','.join(inners))
    return collection_id
Ejemplo n.º 5
0
 def run(self):
     if not os.path.isdir(self.cur_dir):
         os.mkdir(self.cur_dir)
         my_log("Album %s created" % self.cur_dir)
     albums, items = self.get_albums_n_items()
     if len(albums) and len(items):
         # If album has another albums and sole items too
         # we should create album for that sole objects
         # because Flickr can not contain sole object with albums in a collection
         self.update_albums(albums)
         new_dir = os.path.join(self.cur_dir, self.name)
         if not os.path.isdir(new_dir):
             os.mkdir(new_dir)
             with open(os.path.join(new_dir, "meta"), "w") as meta:
                 meta.write(self.get_meta(new_dir))
         self.update_items(items, new_dir)
     elif len(albums):
         self.update_albums(albums)
     else:
         self.update_items(items, self.cur_dir)
     with open(os.path.join(self.cur_dir, "meta"), "w") as meta:
         meta.write(self.get_meta(self.cur_dir))
     return self