def _item_to_restaurant_result(item): d = dynamodb.item_to_dict(item) imagepath = '{0}{1}/{2}'.format( dynamodb.get_env('IMAGE_SERVER_PREFIX'), dynamodb.get_env('IMAGE_SERVER'), item.get('path')) return { 'name': d.get('name_en', ''), 'path': imagepath if d.has_key('path') else '', }
def _dish_to_json_dict(order, item): imagepath = '{0}{1}/{2}'.format( dynamodb.get_env('IMAGE_SERVER_PREFIX'), dynamodb.get_env('IMAGE_SERVER'), item.get('path')) return { 'order': order, 'id': item.get('id', ''), 'priority': item.get('_cmp', 999999999), 'name': item.get('name_en'), 'description': item.get('description', ''), 'tags': item.get('tags', '').split(','), 'image': imagepath if item.has_key('path') else '', }
def _save_images(): # validate uploaded thing uploaded = request.files.get('upload') if not _validate_uploaded(uploaded.filename): raise HTTPError(400, "File is not allowed") # save to local (_, suffix) = os.path.splitext(uploaded.filename.lower()) tmp_directory = '/tmp/{0}'.format('uploaded') tmp_filename = '{0}'.format(str(uuid.uuid4())) if not os.path.exists(tmp_directory): os.makedirs(tmp_directory) savepath = '{0}{1}'.format(os.path.join(tmp_directory, tmp_filename), suffix) uploaded.save(savepath) # convert thumb thumb_file = 'thumb-{0}.jpg'.format(tmp_filename) thumb_path = os.path.join(tmp_directory, thumb_file) cmds = ['convert', '-resize', '320x', savepath, thumb_path] subprocess.call(cmds) # upload to s3 s3bucket = dynamodb.get_env('IMAGE_S3_BUCKET') s3path = 'images/{0}'.format(thumb_file) s3.upload(thumb_path, s3bucket, s3path) return s3path