break offset += 20 parse_posts(content, t) return images def parse_posts(posts, t): images = [] for post in posts["posts"]: if post.get("body") is None: print post continue regex_res = REGEX.search(post["body"]) title = post["title"] source = post["post_url"] #tags = post["tags"] # sometimes we can have some surprises... if regex_res is None: print post continue image_url = regex_res.group(0) t.add_image(image_url, source, title) return images if __name__ == '__main__': tumblrs = ['lesjoiesdusysadmin.tumblr.com', 'devopsreactions.tumblr.com', 'lesjoiesducode.fr', 'lifeofasoftwareengineer.tumblr.com', 'frontenddevreactions.tumblr.com'] t = ItGifs() for tumblr in tumblrs: print tumblr get_posts(tumblr, t) t.close()
images = gifs.get_image_with_id(idimg) if not images: return jsonify({"error": "not found"}), 404 return jsonify(images), 200 @app.route("/", methods=["POST"]) def create_gif(): if request.headers.get('Content-Type') == 'application/json': content = request.get_json() url, source, tags = content.get("url"), content.get("source"), content.get("tags") else: url, source, tags = request.form.get("url"), request.form.get("source"), request.form.get("tags") if not url or not source or not tags: return jsonify({"error": "missing parameter"}), 416 ret = gifs.add_image(url, source, tags) return jsonify({"added": ret}), 200 @app.route("/id/<int:img_id>", methods=["DELETE"]) def delete_gif(img_id): gifs.del_image(img_id) return jsonify({}), 200 if __name__ == "__main__": dispatcher = wsgiserver.WSGIPathInfoDispatcher({'/': app}) server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), dispatcher) try: server.start() except KeyboardInterrupt: server.stop() gifs.close()