def add_movie(chat_id, movie_name): querystring = {"query": movie_name.replace(" ", "+"), "n": 1} response = requests.request("GET", secret_settings.url_movieglu_api + "filmLiveSearch/", headers=secret_settings.headers_movieglu_api, params=querystring) movie_id = response.json()['films'][0]['film_id'] movie = get_movie_details(movie_id) movie = movie.json() movie_det = { "film_id": movie_id, "movie_name": movie_name, "genre": movie['genres'][0]['genre_id'] if movie['genres'] else None, "cast": [c['cast_id'] for c in movie["cast"]], "directors": [c['director_id'] for c in movie["directors"]] } DB.DBManagement().insert_movie(chat_id, movie_det)
def start(bot, update): chat_id = update.message.chat_id db_management.DBManagementHelper().update_index(chat_id, 0) db_management.DBManagement().update_movie(chat_id) exist_user = "" if not model.add_user(chat_id): model.update_status(chat_id, 'start') exist_user = "******" message = f"Welcome {exist_user} to Go2Movie bot!\n" \ "Give me an example of a movie you like and I'll find you a movie you'll like." logger.info(f"> Start chat #{chat_id}") keyboard = [[InlineKeyboardButton("Add movie", callback_data='1')]] if not exist_user else \ [[InlineKeyboardButton("Add movie", callback_data='1'), InlineKeyboardButton("Get recommendations", callback_data='2')]] reply_markup = InlineKeyboardMarkup(keyboard) bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup)
def add_user(chat_id): if not DB.DBManagement().find_user(chat_id): DB.DBManagement().insert_user(chat_id) return True return False
def get_status(chat_id): return DB.DBManagement().get_status(chat_id)
def get_lon(chat_id): return DB.DBManagement().get_lon(chat_id)
def update_lat(chat_id, lat): DB.DBManagement().update_lat(chat_id, lat)
def update_lon(chat_id, lon): DB.DBManagement().update_lon(chat_id, lon)
def get_all_movies(chat_id): return DB.DBManagement().get_all_movies(chat_id)
def get_date(chat_id): return DB.DBManagement().get_date(chat_id)
def choose_date(chat_id, date=datetime.datetime.now(), is_notification=True): DB.DBManagement().insert_date(chat_id, date, is_notification)
def delete_all_movies(chat_id): DB.DBManagement().delete_all_movies(chat_id)
def update_status(chat_id, status): DB.DBManagement().update_status(chat_id, status)
def get_chosen_movie(chat_id): return DB.DBManagement().get_chosen_movie(chat_id)
def choose_movie(chat_id, movie): DB.DBManagement().insert_chosen_movie(chat_id, movie)