def getRecommend(uid): result = findAllJson2() recomm = getRecommendations(result, uid) resultjson = '' list1 = [] dbutils = DBUtils(host, user, password, db, port) movie_list = [] if recomm[0][1]: print(recomm[0][1]) for i in range(5): redc = recomm[i][1] list1.append(redc) for item in list1: movie_item = getMovieByName(dbutils, item) movie_list.append(movie_item) else: sql = 'select * from movie where id<6' result = dbutils.query(sql) for item in result: movie_item = {} movie_item['id'] = item[0] movie_item['movieName'] = item[1].strip() movie_item['src'] = item[7] movie_item['averating'] = item[9].strip() movie_item['playPage'] = item[8] movie_item['fileName'] = item[10] movie_list.append(movie_item) dbutils.close() print(movie_list) return movie_list
def getMovieList(): dbutils = DBUtils(host, user, password, db, port) sql = 'select * from movie' result = dbutils.query(sql) movie_list = [] for item in result: movie_item = {} movie_item['id'] = item[0] movie_item['movieName'] = item[1].strip() movie_item['src'] = item[7] movie_item['averating'] = item[9].strip() movie_list.append(movie_item) dbutils.close() return movie_list
def getHistoryList(uid): dbutils = DBUtils(host, user, password, db, port) sql = 'select distinct m.id,m.movieName,m.movieType,m.director,m.star,m.release,m.language,m.coverUrl,m.playPage,m.averageScore,' \ 'm.fileName,m.year from movie as m join history ' \ 'as h where h.uid=%d and m.id = h.mid;' % int(uid) result = dbutils.query(sql) movie_list = [] for item in result: movie_item = {} movie_item['id'] = item[0] movie_item['movieName'] = item[1] movie_item['src'] = item[7] movie_item['averating'] = item[9] movie_list.append(movie_item) dbutils.close() return movie_list
def getMovieById(id): dbutils = DBUtils(host, user, password, db, port) sql = 'select * from movie where id=%d' % id result = dbutils.query(sql) movie = {} for item in result: movie['id'] = item[0] movie['name'] = item[1].strip() movie['src'] = item[7].strip() movie['averating'] = item[9].strip() movie['year'] = item[11] movie['director'] = item[3].strip() movie['star'] = item[4].strip() movie['type'] = item[2].strip() movie['language'] = item[6].strip() movie['release'] = item[5].strip() movie['playPage'] = item[8] movie['fileName'] = item[10] dbutils.close() return movie