def add_learning_object(query, connection=None): assert query.get("name", None) if find_one({"name": query["name"]}, "prono", "learning_objects"): return "learning object named %s already exists" % (query["name"]) return insert(query, "prono", "learning_objects", connection)
def add_team(query, verbose=False): assert query["name"] assert query["link"] if verbose: print "Do you want to add the team {\"name\": %s, \"link\": %s} [Y/n]:" % (query["name"], query["link"]) while 42: line = os.sys.stdin.readline() line = line[:-1] if line in ["Y", "y", "yes"]: break elif line in ["N", "n", "no"]: return else: print "[Y/n]:" old = find_one({"link": query["link"]}, "prono", "teams") if old is None: print "added team :", query["name"] return insert(query, "prono", "teams") else: if old["name"] != query["name"]: print old["name"] print query["name"] print # print ret # print "%s already inserted" % (query["name"]) return None
def add_season(query): db_query = dict() assert query.get("championship", None) assert query.get("years", None) assert len(query["years"]) == 2 assert query.get("games", None) db_query["championship"] = find_championship( {"name": query["championship"]}) if not db_query["championship"]: raise Exception("championship name not found") db_query["championship"] = db_query["championship"]["_id"] db_query["years"] = query["years"] db_query["games"] = dict() for day in query["games"]: print "======== %s journee =========" % (day) db_query["games"][day] = list() for game in query["games"][day]: print normalize(game["team_H"]), "-", normalize(game["team_A"]) db_game = dict() db_game["team_H"] = find_team_by_name(normalize( game["team_H"]))["_id"] if not db_game["team_H"]: raise Exception("home team : %s not found" % game["team_H"]) db_game["team_A"] = find_team_by_name(normalize( game["team_A"]))["_id"] if not db_game["team_A"]: raise Exception("away team : %s not found" % game["team_A"]) db_game["date"] = game["date"] db_game["link"] = game["link"] db_game["score"] = { "score_H": game["score"]["score_H"], "score_A": game["score"]["score_A"] } game_id = insert(db_game, "prono", "games") db_query["games"][day].append(game_id) return insert(db_query, "prono", "seasons")
def save_to_db(self, name): if self.client_db is None: self.client_db = get_db("prono", mongolab=True) to_save = { "name": name, "params": self.params, "nn": pickle.dumps(self.nn), "scalizer": pickle.dumps(self.scalizer), "normalizer": pickle.dumps(self.normalizer) } return insert(to_save, "prono", "learning_objects", connection=self.client_db)
def add_stadium(query): assert query["name"] old = find_stadium_by_name(query["name"]) if old is None: return insert(query, "prono", "stadiums") else: if old["name"] != query["name"]: print old["name"] print query["name"] print # print ret # print "%s already inserted" % (query["name"]) return None
def add_people(query): assert query.get("name", None) assert query.get("link", None) old = find_people_by_link(query["link"]) if old == None: return insert({ "name": query["name"], "link": query["link"] }, "prono", "peoples") elif old["name"] != query["name"]: print query["name"], "is already existing with this name :" return add_people_alias(old["name"], query["name"]) else: return None
def add_game(query, connection=None): # print query new_game = dict() assert query.get("team_H") assert query.get("team_A") assert query.get("link") old_game = find_game_by_link(query["link"], connection) if old_game != None: print "game \"" + query["link"] + "\" already exists in DB." return None team_H = find_team_by_link(query["team_H"]["link"], connection) # print query["team_H"]["link"], team_H if not team_H: add_team(query["team_H"], verbose=False) team_H = find_team_by_link(query["team_H"]["link"], connection) if team_H is None: # print "OUT 1" return None new_game["team_H"] = get_correct_team_id(team_H["_id"], query["link"]) team_A = find_team_by_link(query["team_A"]["link"], connection) if not team_A: add_team(query["team_A"], verbose=False) team_A = find_team_by_link(query["team_A"]["link"], connection) if team_A is None: # print "OUT 2" return None new_game["team_A"] = get_correct_team_id(team_A["_id"], query["link"]) stadium = find_stadium_by_name(query.get("stadium", ""), connection) if stadium: new_game["stadium"] = stadium["_id"] region = find_region_by_name(query.get("region", ""), connection) if region: new_game["region"] = region["_id"] new_game["date"] = query.get("date", "") new_game["link"] = query.get("link", "") new_game["start_time"] = query.get("start_time", "") new_game["score"] = query.get("score", "") new_game["division"] = query.get("division", "") # print "new game =", new_game return insert(new_game, "prono", "games", connection)
def add_competition(query): assert query.get("name", None) assert query.get("region", None) if find_one({"name": query["name"]}, "prono", "competitions"): return "competition already exists" region = find_one({"name": query["region"]}, "prono", "regions") if region == None: add_region({"name": query["region"]}) region = find_one({"name": query["region"]}, "prono", "regions") region_id = region["_id"] return insert({ "name": query["name"], "region": region_id }, "prono", "competitions")
def add_region(query): assert query.get("name", None) return insert({"name": query["name"]}, "prono", "regions")