def heromodify(): try: db = inicializar_db_heroes() id = request.json["id"] name = request.json["name"] character = request.json["character"] biography = request.json["biography"] house = request.json["house"] year = request.json["year"] images = request.json["images"] equipment = request.json["equipment"] img_count = request.json["img_count"] nuevo = { "name": name, "character": character, "biography": biography, "house": house, "year": year, "images": images, "equipment": equipment, "img_count": img_count } db.list.update_one({"_id": ObjectId(id)}, {"$set": nuevo}) return "OK" except (Exception) as err: return str(err), 500
def herodelete(): try: id = request.json["id"] db = inicializar_db_heroes() res = db.list.delete_one({"_id": ObjectId(id)}) return "OK" except (Exception) as err: return str(err), 500
def heroget(): try: id = request.json["id"] db = inicializar_db_heroes() res = db.list.find_one({"_id": ObjectId(id)}) res["_id"] = str(res["_id"]) return jsonify(res) except (Exception) as err: return str(err), 500
def movieadd(): try: db = inicializar_db_movies() title = request.json["title"] id = request.json["id"] release_date = request.json["release_date"] overview = request.json["overview"] poster_path = request.json["poster_path"] cast = request.json["cast"] #buscamos todos los heroes y linkeamos las peliculas db2 = inicializar_db_heroes() for element in cast: hero = None #si esta dividido por / if '/' in element["character"]: names = element["character"].split(' / ') for name in names: if (hero == None): hero = db2.list.find_one( {"$text": { "$search": "\"" + name + "\"" }}) else: break else: hero = db2.list.find_one( {"$text": { "$search": "\"" + element["character"] + "\"" }}) if (hero != None): db2.list.update_one( {"_id": hero["_id"]}, {"$push": { "movies": { "id": id, "title": title } }}) element["id_hero"] = str(hero["_id"]) nuevo = { "id": id, "title": title, "release_date": release_date, "overview": overview, "poster_path": poster_path, "cast": cast } db.list.insert_one(nuevo) return "OK" except (Exception) as err: return str(err), 500
def herolistdc(): try: db = inicializar_db_heroes() res = [] for x in db.list.find({"house": "DC"}): x["_id"] = str(x["_id"]) res.append(x) return jsonify(res) except (Exception) as err: return str(err), 500
def cargar_db(): try: db1 = inicializar_db_heroes() db2 = inicializar_db_movies() db2.list.drop() cargar_datos_heroes(db1) db1.list.create_index([('name', TEXT), ('character', TEXT)]) return "OK" except (Exception) as err: return str(err), 500
def heroadd(): try: db = inicializar_db_heroes() name = request.json["name"] character = request.json["character"] biography = request.json["biography"] house = request.json["house"] year = request.json["year"] images = request.json["images"] if 'equipment' in request.json: equipment = request.json["equipment"] nuevo = { "name": name, "character": character, "biography": biography, "house": house, "year": year, "images": images, "equipment": equipment, "img_count": len(images) } else: nuevo = { "name": name, "character": character, "biography": biography, "house": house, "year": year, "images": images, "img_count": len(images) } db.list.insert_one(nuevo) return "OK" except (Exception) as err: return str(err), 500