def _CreateFormats(): """Used to set up initial photos.""" obj_store = ObjectStore.GetInstance(ObjectStore.PHOTO) client = DBClient.Instance() http_client = AsyncHTTPClient() for photo_id, name in [('pgAZn77bJ-Kc', 'beach_c4'), ('pgAzpz7bJ-Mc', 'beach_a1'), ('pgB-Fh7bJ-Mg', 'beach_a2'), ('pgAzo67bJ-MV', 'beach_a3'), ('pgB-pj7bJ-Mo', 'beach_a4'), ('pgAvIa7bJ-MN', 'beach_b1'), ('pgAuoQ7bJ-MF', 'beach_b2'), ('pgAtwd7bJ-M7', 'beach_b3'), ('pgAaOJ7bJ-Kw', 'beach_c1'), ('pgA_vm7bJ-Ko', 'beach_c2'), ('pgAZna7bJ-Kk', 'beach_c3'), ('pgAW0x7bJ-KV', 'beach_d1'), ('pgAUMm7bJ-KN', 'beach_d2'), ('pfYwYR7bJ-KJ', 'party_1'), ('pfYwTk7bJ-KF', 'party_2'), ('pfYwSo7bJ-K7', 'party_3'), ('pfYw0g7bJ-K-', 'party_4'), ('pfYvoK7bJ-Jw', 'party_5'), ('pfYvhI7bJ-Jo', 'party_6'), ('prHKwa7bJ-N30', 'gone_fishing_1'), ('prBUtl7bJ-Mw', 'gone_fishing_2'), ('pfSb0S7bJ-Jk', 'street_art_1'), ('pfSasJ7bJ-Jc', 'street_art_2')]: photo = yield Photo.Query(client, photo_id, None) photo_dict = photo._asdict() photo_dict['name'] = name del photo_dict['photo_id'] del photo_dict['user_id'] del photo_dict['_version'] del photo_dict['episode_id'] print json.dumps(photo_dict, indent=True) for suffix, format in [('.f', 'full'), ('.m', 'med'), ('.t', 'tn')]: url = obj_store.GenerateUrl('%s%s' % (photo_id, suffix)) response = yield http_client.fetch(url, method='GET') welcome_path = os.path.join( ResourcesManager.Instance().resources_path, 'welcome') f = open( os.path.join(welcome_path, '%s_%s.jpg' % (name, format)), 'w') f.write(response.body) f.close()
def _OnQueryPosts(posts): with util.ArrayBarrier(partial(_OnQueryMetadata, posts)) as b: for post in posts: with util.ArrayBarrier(b.Callback()) as metadata_b: post_id = Post.ConstructPostId(post.episode_id, post.photo_id) Photo.Query(client, hash_key=post.photo_id, col_names=None, callback=metadata_b.Callback()) UserPost.Query(client, hash_key=user_id, range_key=post_id, col_names=None, callback=metadata_b.Callback(), must_exist=False)
def _OnCreatePhoto(p): Photo.Query(self._client, p.photo_id, None, _OnQuery)
def _OnCreatePhoto(p): Photo.Query(self._client, p.photo_id, None, partial(_OnQuery, p))