示例#1
0
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)
示例#2
0
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)
示例#3
0
def add_user(chat_id):
    if not DB.DBManagement().find_user(chat_id):
        DB.DBManagement().insert_user(chat_id)
        return True
    return False
示例#4
0
def get_status(chat_id):
    return DB.DBManagement().get_status(chat_id)
示例#5
0
def get_lon(chat_id):
    return DB.DBManagement().get_lon(chat_id)
示例#6
0
def update_lat(chat_id, lat):
    DB.DBManagement().update_lat(chat_id, lat)
示例#7
0
def update_lon(chat_id, lon):
    DB.DBManagement().update_lon(chat_id, lon)
示例#8
0
def get_all_movies(chat_id):
    return DB.DBManagement().get_all_movies(chat_id)
示例#9
0
def get_date(chat_id):
    return DB.DBManagement().get_date(chat_id)
示例#10
0
def choose_date(chat_id, date=datetime.datetime.now(), is_notification=True):
    DB.DBManagement().insert_date(chat_id, date, is_notification)
示例#11
0
def delete_all_movies(chat_id):
    DB.DBManagement().delete_all_movies(chat_id)
示例#12
0
def update_status(chat_id, status):
    DB.DBManagement().update_status(chat_id, status)
示例#13
0
def get_chosen_movie(chat_id):
    return DB.DBManagement().get_chosen_movie(chat_id)
示例#14
0
def choose_movie(chat_id, movie):
    DB.DBManagement().insert_chosen_movie(chat_id, movie)