def add_new_link(data): col = Connection.db()["links"] return col.insert({ 'movieId': data['movieId'], 'tmdbId': data['tmdbId'] })
def add_info_into_sign_request(document_id1, user_id1): document_id = str(document_id1) user_id = str(user_id1) conn = Connection.instance() print(document_id, user_id) conn.execute_query5( "insert into sign_request(document_id,user_id, is_signed) values(%s,%s, false)", document_id, user_id)
def get_all_movies_genres(): col_movies = Connection.db()["movies"] base_movies = {} for data in col_movies.find(): base_movies[data['movieId']] = (data['genres'], data['year']) return base_movies
def get_movie_api(movie_id): # COLEÇÃO DE FILMES col_movies = Connection.db()["movies"] data = col_movies.find_one({"movieId": movie_id}) return { "movieId": data['movieId'], "title": data['title'], "genres": data['genres'], "year": data['year'], }
def find_all(address): conn = Connection.instance() print(address) db_res = conn.execute_query( "select id, owner_id, title, description, creation_time, update_time, is_signed from document t join sign_request s on s.document_id=t.id where s.user_id=%s", address) documents = [] for row in db_res: documents.append(build_document_from_row(row)) return documents
def message_socket(ws: WebSocket, connection: Connection) -> None: if Api.__COOKIE_SESSION_NAME not in session: ws.close() return db_session = connection.session() for post in db_session.query(Post).all(): ws.send( Message(datetime=floor(post.datetime.timestamp()), author=post.author, text=post.message).serialize()) with MessageSubscribersQueue.subscribe(request, ws): ws.receive()
def authorization( user: User, connection: Connection) -> Union[Response, Serializable]: if len(user.name) > 150: return Response(status=HTTPStatus.BAD_REQUEST) db_session = connection.session() db_user = db_session.query(DB_User).filter( DB_User.user_name == user.name).first() if db_user is None or db_user.password != PasswordHasher.get_hash( db_user.salt, user.password): return Result(StatusCode.InvalidUsernameOrPassword.name) session[Api.__COOKIE_SESSION_NAME] = UserIdPrincipal(user.name) return Result(StatusCode.Success.name)
def send_message( message: MessageToSend, connection: Connection) -> Union[Response, Serializable]: if len(message.text) > 280: return Response(status=HTTPStatus.BAD_REQUEST) post = Post(datetime=datetime.utcnow(), author=session[Api.__COOKIE_SESSION_NAME]["name"], message=message.text) db_session = connection.session() db_session.add(post) MessageSubscribersQueue.send_to_subscribers( Message(floor(post.datetime.timestamp()), post.author, post.message)) db_session.commit() return Result(StatusCode.Success.value)
def get_movies(with_context): # COLEÇÃO DE AVALIAÇÕES col_ratings = Connection.db()["ratings"] # INICIA A BASE DE AVALIACOES base_ratings = {} for data in col_ratings.find(): base_ratings.setdefault(data['userId'], {}) # APLICAÇÃO DO CONTEXTO -> FILTRA AS AVALIACOES PELO CONTEXTO(SE É FIM DE SEMANA OU NÃO) if with_context and not Util.is_context_dayweek( datetime.fromtimestamp(float( data['timestamp'])).weekday()): continue base_ratings[data['userId']][data['movieId']] = float( data['rating']) return base_ratings
def find_counters(address): conn = Connection.instance() db_res = conn.execute_query3( "select count(*) from sign_request where user_id=%s and is_signed=false", address) db_res1 = conn.execute_query3( "select count(*) from document t join sign_request s on s.user_id=t.owner_id where t.owner_id=%s and is_signed=false", address) db_res2 = conn.execute_query3( "select count(*) from sign_request where user_id=%s", address) db_res3 = conn.execute_query3( "select count(*) from document t join sign_request s on s.user_id=t.owner_id where t.owner_id=%s ", address) counters = MainEntity() counters.income = db_res[0] counters.outcome = db_res1[0] counters.total_income = db_res2[0] counters.total_outcome = db_res3[0] # counters.serialize() print(counters) return counters.serialize()
def registration( user: User, connection: Connection) -> Union[Response, Serializable]: if len(user.name) > 150: return Response(status=HTTPStatus.BAD_REQUEST) db_session = connection.serializable_session() if db_session.query(exists().where( connection.User.user_name == user.name)).scalar(): return Result(StatusCode.UserAlreadyExist.name) salt = os.urandom(32) db_session.add( DB_User(user_name=user.name, password=PasswordHasher.get_hash(salt, user.password), salt=salt)) db_session.commit() session[Api.__COOKIE_SESSION_NAME] = UserIdPrincipal(user.name) return Result(StatusCode.Success.name)
from ApiProvider import ApiProvider from controller.DataLoader import load_song_data from controller.RecommendationTool import create_recommended_playlist from db.Connection import Connection api = ApiProvider.get_api() load_song_data(api) create_recommended_playlist(api) # create_artist_playlist(api, 3372, True) Connection.instance().close()
def get_movies_links(): col_links = Connection.db()["links"] return col_links.find()
def get_movie_genre(genre): col_movies = Connection.db()["movies"] return col_movies.find_one({"genres": genre})
def get_categories(movieId): col_tabs = Connection.db()["movies"] return col_tabs.find_one({"movieId": movieId})["genres"]
def get_tags_movie(movieId): col_tabs = Connection.db()["tags"] return col_tabs.find({"movieId": movieId})
def add_info_into_documents(id, owner_id, title, description): conn = Connection.instance() conn.execute_query4( "insert into document(id, owner_id, title, description,creation_time,update_time) values(%s,%s,%s,%s, current_date,current_date)", id, owner_id, title, description)
def update_status(address, id): conn = Connection.instance() conn.execute_query6( "update sign_request set is_signed=true where document_id=%s and user_id=%s", address, id)
def get_tmdb_exist(tmdbId): col = Connection.db()["links"] return col.find_one({"tmdbId": tmdbId})
def get_all_movies_per_genre(genres): # COLEÇÃO DE FILMES col_movies = Connection.db()["movies"] return col_movies.find({"genres": {"$" "in": genres}})
def get_all_movies(): col_movies = Connection.db()["movies"] return col_movies.find()
def get_movie_link(movie_id): col_links = Connection.db()["links"] return col_links.find_one({'movieId': movie_id})
def __config(binder: Binder) -> None: binder.bind(Flask, Flask("res")) binder.bind(Connection, Connection())
def add(data): col_users = Connection.db()["users"] return col_users.insert(data)
def get_user_ratings(user_id): # COLEÇÃO DE AVALIAÇÕES DO USUARIO col_movies = Connection.db()["ratings"] return col_movies.find({"userId": user_id})
def get_rating(movie_id): # COLEÇÃO DE FILMES col_movies = Connection.db()["ratings"] return col_movies.find_one({"movieId": movie_id})
def get_tmdb_id(movieId): col = Connection.db()["links"] return col.find_one({"movieId": movieId})
def get_cursor(): return Connection.instance().get_cursor()
def find_by_id(id): conn = Connection.instance() db_res = conn.execute_query1("select * from document t where id=%s", id) row = db_res return build_document_from_row(row)