def get(self): """ To avoid doing long requests, just get the full list of images, then randomize it, and download the 10 first ones. Anyway, this will be cron'd, so we'll in the end get all images. """ content = urllib2.urlopen("http://bukk.it").read() image_names = re.findall('<td><a href="(.*?)">(?:.*?)</a>', content, re.DOTALL) random.shuffle(image_names) i = 0 for image_name in image_names: url = "http://bukk.it/" + image_name logging.info(">>> Stealing bukkit image: " + image_name + " (url: " + url + ")") model.store_image(url, image_name) i += 1 if i > 10: break self.response.out.write("done ... downloaded 10 images on bukkit")
def upload_file(): if 'file' not in request.files: return jsonify({"error": "no file provided"}), 400 file = request.files['file'] if file.filename == '': return jsonify({"error": "no file provided"}), 400 type_allowed, extension = allowed_file(file.filename) if not file or not type_allowed: return jsonify({"error": "disallowed file extension"}), 400 image_name = request.form.get("name", "Unknown") id = str(uuid.uuid4()) image_file = id + "." + extension img_file = os.path.join(app.config['UPLOAD_FOLDER'], image_file) file.save(img_file) store_image(img_file, image_file, image_name, id) return jsonify({"status": "Success"}), 201
def post(self): is_done = model.store_image( self.request.get("url"), self.request.get("file_name")) if is_done: self.response.out.write( "Image " + self.request.get("file_name") + " added ! (from: " + self.request.get("url") + ").<br /><img src='/img/" + self.request.get("file_name") + "' /><br /><a href='/__/upload'>Add an other image</a>") else: self.response.out.write( "Sorry, could not add image. Either there's already an image with the same name or the image couldn't be uploaded (probably more than 1Mb).<br /><a href='/__/upload'>Try again</a>" )