def test_find_good(app): """ Тест с ожидаемым пололжительным результатом, что фильм найдется """ # вход в систему app.login_in_system(User.Admin()) # добавим два фильма для тестирования поиска app.fill_movie_form(Film.goneWind(), True, True) # первый app.fill_movie_form(Film.weryDanger(), True, True) # второй # смотрим и запоминаем сколько есть фильмов first_len_boxes = app.films_on_main_page() # поищем первый фильм по поиску app.find_film(Film.goneWind()) # смотрим и запоминаем сколько стало фильмов last_len_boxes = app.films_on_main_page() # сравниваем до и после, если изменилось, поиск работает, но необходимо убедиться, что нашлось, то что нужно if first_len_boxes == last_len_boxes: raise AssertionError, u"Количество фильмов не изменилось, возможно поиск не работает" else: # проверим, если тут искомый фильм app.give_this_film(Film.goneWind()) # если есть, и можно кликнуть, то все хорошо app.logout()
def test_find_bad(app): """ Тест с ожидаемым отрицательным результатом, что фильм не найдется """ # вход в систему app.login_in_system(User.Admin()) # добавим два фильма для тестирования поиска app.fill_movie_form(Film.goodFilm(), True, True) app.fill_movie_form(Film.veryGoodFilm(), True, True) # попробуем поискать несуществующий фильм, но сначала убедимся, что его нету в каталоге try: app.give_this_film(Film.randomFilm()) so_bad = 1 except NoSuchElementException: # если не получилось найти, то можно проверять поиск по нему so_bad = 0 if so_bad == 0: # поищем рандомный фильм по поиску app.find_film(Film.randomFilm()) # Убедимся, что не отображается никаких найденных фильмов на странице no_movies = app.verify_no_movies() assert (no_movies, "No movies where found.") if so_bad == 1: raise AssertionError, u"Нашелся какой то фильм, нужно взять на тестирование несуществующий" app.logout()
def test_create_film_good(app): """ Проверяет создание фильма """ app.login_in_system(User.Admin()) app.fill_movie_form(Film.madagaskar(), True) # проверим, что правильно занеслись данные title_elem = app.header_now_added_film() valid_title_elem = Film.madagaskar().name + " (" + Film.madagaskar().year + ")" # формируем проверочную строку assert (title_elem, valid_title_elem) # проверим, что он отображается на главной странице и на него можно перейти app.film_exist_on_main_page(Film.madagaskar()) app.logout()
def delete_all(): ndb.delete_multi(Trailer.query().fetch(keys_only=True)) ndb.delete_multi(Film.query().fetch(keys_only=True)) ndb.delete_multi(Actor.query().fetch(keys_only=True)) ndb.delete_multi(Genre.query().fetch(keys_only=True)) ndb.delete_multi(Producer.query().fetch(keys_only=True)) ndb.delete_multi(Director.query().fetch(keys_only=True))
def __process_genre(self, name, t, g, is_film_object): if damerau_levenshtein_distance(de_uncd(name), t) < 2: if not self.data.genre: self.data.genre = [] if is_film_object: films = get_genres(g.kinohod_id) for f in films: film_id = f.get('id') if not film_id or film_id in self.__ids_inside: continue o = Film.get_by_id(film_id) if not o: schedules = get_schedule(film_id) o = set_film_model(f, schedules) self.__ids_inside.append(film_id) self.data.genre.append(o) else: self.data.genre += get_genres(g.kinohod_id) return True return False
def setUp(self): self.series = Series(Mongo('movies')) self.a_film = Film() self.a_film.id = 1 self.a_film.description = "description" self.a_film.director = "director" self.a_film.name = "name" self.a_film.seasons = "season" self.a_film.year = "2016" self.other_film = Film() self.other_film.id = 2 self.other_film.description = "description_other" self.other_film.director = "director_other" self.other_film.name = "name_other" self.other_film.seasons = "season_other" self.other_film.year = "2017"
def LoadData(jsonPath): with open(jsonPath) as film_file: jsFilm = json.load(film_file) movieFrame = [] for jsFrame in jsFilm["frames"]: movieFrame.append(Frame(jsFrame["num"], jsFrame["primalColor"])) film = Film(jsFilm["titre"], movieFrame) return film
def test_create_film_bad(app): """ Пробует создать фильм с незаполненными обязательными полями """ app.login_in_system(User.Admin()) app.fill_movie_form(Film.pirates()) app.clear_and_check_required_fields() app.logout()
def callback_seance_text(tuid, bot, chat_id, text, cmd, profile): # in profile.cmd should be movie id # need concatenate movie with place if 'num' not in profile.cmd: return i_n = profile.cmd.index('num') movie_id = profile.cmd[len('/location'):i_n] film = Film.get_by_id(movie_id) cmd = cmd.encode('utf-8') # poor place of the code - every time new request to kinohod db film_cinemas, city_id = detect_film_cinemas(chat_id, movie_id, date=None) if not film_cinemas or len(film_cinemas) < 1: bot.sendMessage(chat_id, settings.NO_FILM_SEANCE) return parser = Parser(request=cmd, state='cinema', city_id=city_id) parser.parse() bot.sendChatAction(chat_id, action='typing') seances = [] if not parser.data.place: pass # bot.sendMessage(chat_id, settings.CINEMA_NOT_FOUND) else: for p in parser.data.place: if not p or p.key not in film_cinemas: continue seances.append( settings.RowCinema(p.shortTitle, p.address, p.mall, '/c{}m{}'.format(p.kinohod_id, movie_id))) if len(seances) < 1: bot.sendMessage(chat_id, settings.NO_FILM_SEANCE) send_reply(bot, chat_id, get_cinemas_where_film, film, settings.CINEMAS_TO_DISPLAY, chat_id) return template = settings.JINJA_ENVIRONMENT.get_template('cinema_where_film.md') msg = template.render({'film_name': film.title, 'seances': seances}) mark_up = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.MORE, callback_data='/where_film{}num{}'.format( film.kinohod_id, settings.CINEMAS_TO_DISPLAY)) ]]) bot.sendMessage(chat_id, msg, parse_mode='Markdown', reply_markup=mark_up)
def get(self, *args, **kwargs): films, places = get_data('film') self.response.write( 'films: {} and db films: {}'.format( str(len(films.values())), str(len(Film.query().fetch())), ) )
def test_add_new_movie(app): app.session.login(username="******", password="******") app.film.click_on_add_movie() app.film.fill_movie_details( Film(imdbid="10", title="My_Film1", year="1990", duration="94", rating="100", format="strange format", known_as="Also known as brbrbr"))
def GetFilmFromDataDir(path): movieNameArray = os.path.basename(path).split("/")[ -1] #Remove the extension movieName = "".join(movieNameArray) monFilm = Film(movieName, []) for file in os.listdir(path): framePath = os.path.join(path, file) if (file.endswith((".jpg"))): monFilm.frames.append( Frame(int(file.replace(".jpg", "")), GetAvgColor(framePath))) return monFilm
def test_add_new_film(app): app.login(User.Admin()) assert app.is_logged_in() before = app.sum_films_collection() # logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') app.add_new_film(Film.random()) after = app.sum_films_collection() assert (after-before) == 1 app.logout() app.ensure_logout
def data2obj(dict): film = Film() if 'title' in dict: film.name = dict['title'] if 'year' in dict: film.year = dict['year'] if 'director' in dict: film.director = dict['director'] if 'summary' in dict: film.summary = dict['summary'] if 'seasons' in dict: film.seasons = dict['seasons'] if 'description' in dict: film.description = dict['description'] return film
def display_info(bot, payload, cmd, chat_id, full=False, prefix_length=len('/info')): t_uid = payload['message']['from']['id'] movie_id = cmd[prefix_length:len(cmd)] if not str(movie_id).isdigit(): bot.sendMessage(chat_id, settings.INFO_NOT_FULL.format(movie_id)) return film = Film.get_by_id(str(movie_id)) now = datetime.now() two_weeks = timedelta(days=14) if not film: return bot.sendMessage(chat_id, settings.DONT_UNDERSTAND) # poor place of whole code film_cinemas, city_id = detect_film_cinemas(chat_id, movie_id, date=None) if (len(film_cinemas) < 1 and not ((film.premiereDateRussia and (now < film.premiereDateRussia < (now + two_weeks))) or (film.premiereDateWorld and (now < film.premiereDateWorld < (now + two_weeks))))): return message, mark_up, movie_poster = display_movie_info(movie_id, t_uid, next_url='/location', full=full) if not message: bot.sendMessage(chat_id, settings.SERVER_NOT_VALID) return if movie_poster: bot.sendChatAction(chat_id, 'upload_photo') bot.sendPhoto(chat_id, ('poster.jpg', movie_poster)) bot.sendMessage(chat_id, message, reply_markup=mark_up, parse_mode='Markdown')
def display_cinemas_where_film(bot, payload, cmd, chat_id): if 'callback_query' not in payload: return bot.answerCallbackQuery(callback_query_id=int( payload['callback_query']['id']), text=':)') index_num = cmd.index('num') movie_id = int(cmd[len('/where_film'):index_num]) num = int(cmd[index_num + len('num'):]) film = Film.get_by_id(str(movie_id)) send_reply(bot, chat_id, get_cinemas_where_film, film, num)
def update_film_table(index_name='films'): films, places = get_data('film') for k, f in films.iteritems(): o = Film.get_by_id(f.get('id')) if not o: o = set_film_model(f) ModelSearch.add_document( ModelSearch.create_film_document( doc_id=o.key.urlsafe(), film=o ), index_name=index_name )
def __add_film(): gui.print_title_new_producer() name = gui.input_data(strings.input_name) location = gui.input_data(strings.input_location) date = gui.input_data(strings.input_date) __show_producers() res = 0 while not res: producer_id = raw_input(strings.input_producer_id) res = __validate_int(producer_id) if res: if not __producers_lab.get_producers().has_key(int(producer_id)): print strings.wrong_input res = 0 __films_lab.add_film( Film(name=name, location=location, date=date, producer_id=producer_id))
def display_future_seances(bot, payload, cmd, chat_id): if 'callback_query' in payload: if '/future' not in cmd: bot.sendMessage(chat_id, settings.SERVER_NOT_VALID) return movie_id = cmd[len('/future'):] film = Film.get_by_id(movie_id) premier = film.premiereDateRussia if not premier or not isinstance(premier, datetime): bot.sendMessage(chat_id, settings.SERVER_NOT_VALID) return send_reply(bot, chat_id, display_seances_all, movie_id, settings.SEANCES_TO_DISPLAY, premier.strftime('%d%m%Y'), success=int(payload['callback_query']['id']))
def process_movies_db(number_of_movies, callback_url, next_url='/info', **kwargs): data = Film.query().order(-Film.rating).fetch( offset=(number_of_movies - settings.FILMS_TO_DISPLAY if number_of_movies > settings.FILMS_TO_DISPLAY else number_of_movies), limit=settings.FILMS_TO_DISPLAY) cinema_id = kwargs.get('cinema_id') separator = kwargs.get('separator') next_info_url = kwargs.get('info_url') videos, premiers = [], [] expanded_info = False for f in data: if cinema_id and separator and next_info_url: expanded_info = True link = '{}{}{}{}'.format(next_url, cinema_id, separator, f.kinohod_id) f_info = IMovieCinema(f.title, link, '{}{}'.format(next_info_url, f.kinohod_id)) else: link = '{}{}'.format(next_url, f.kinohod_id) f_info = settings.Row(settings.uncd(f.title), link) if f.premiereDateRussia: now = datetime.utcnow() if f.premiereDateRussia > now: premiers.append(f_info) else: videos.append(f_info) else: premiers.append(f_info) mark_up = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.MORE, callback_data=( callback_url.format(number_of_movies + 2 * settings.FILMS_TO_DISPLAY))) ]]) if expanded_info: template = ( settings.JINJA_ENVIRONMENT.get_template('running_movies_ext.md')) msg = template.render({ 'videos': videos, 'premiers': premiers, 'sign_video': settings.SIGN_VIDEO, 'sign_tip': settings.SIGN_TIP, 'sign_calendar': settings.SIGN_CALENDAR, 'sign_newspaper': settings.SIGN_NEWSPAPER, 'sign_premier': settings.SIGN_PREMIER }) else: template = settings.JINJA_ENVIRONMENT.get_template('running_movies.md') msg = template.render({ 'videos': videos, 'premiers': premiers, 'sign_video': settings.SIGN_VIDEO, 'sign_tip': settings.SIGN_TIP, 'sign_premier': settings.SIGN_PREMIER }) return msg, mark_up
def action(self, menu_item): if menu_item == 1: name = str(raw_input("Enter name of new producer: ")) surname = str(raw_input("Enter surname: ")) self.__add_producer(name, surname) elif menu_item == 2: name = raw_input("Enter name of film: ") country = raw_input("Enter country: ") self.__display_producers() producer = int(raw_input("Enter producer index: ")) - 1 if 0 <= producer < len(self.__list_of_producers): self.__add_film(Film(name, country), self.__list_of_producers[producer]) else: print "Incorrect index" elif menu_item == 3: self.__display_producers() elif menu_item == 4: self.__display_films() elif menu_item == 5: self.__display_producers() index = int(input("Enter producer index: ") - 1) if 0 <= index < len(self.__list_of_producers): self.__delete_producer(self.__list_of_producers[index]) else: print "Failed index!" elif menu_item == 6: self.__display_films() index = int(input("Enter film index: ")) - 1 if 0 <= index < len(self.__list_of_films): self.__delete_film(self.__list_of_films[index]) else: print "Failed index!" elif menu_item == 7: self.__display_producers() index = int(input("Enter producer index: ")) - 1 if index < 0 or index >= len(self.__list_of_producers): print "Failed index!" else: producer = self.__list_of_producers[index] name = raw_input("Enter new name: ") if name == "": name = producer.name surname = raw_input("Enter new surname: ") if surname == "": surname = producer.surname self.__edit_producer(producer, name, surname) elif menu_item == 8: self.__display_films() index = int(input("Enter film index: ")) - 1 if 0 <= index < len(self.__list_of_films): film = self.__list_of_films[index] name = raw_input("Enter new name of film: ") country = raw_input("Enter new country of filmed: ") self.__display_producers() producer_index = int(input("Enter producer index: ")) - 1 if not 0 <= index < len(self.__list_of_producers): print "Incorrect producer!" return if name == "": name = film.name if country == "": country = film.country self.__edit_film(film, name, country, self.__list_of_producers[producer_index]) elif menu_item == 9: self.__display_filmed_in_ukraine()
def display_movie_info(movie_id, telegram_user_id=None, next_url='/seance', full=False): now = datetime.now() film = Film.get_by_id(str(movie_id)) telegram_user_id = telegram_user_id if telegram_user_id else 0 if not film: display_movie_info_api(movie_id, telegram_user_id, next_url='/seance') if film.poster: movie_poster = _get_movie_poster(film.poster.name) else: movie_poster = None if film.trailers and len(film.trailers) > 0: trailer = film.trailers[0].get() if trailer is not None: video_hash = trailer.videos[0].filename trailer_url = _get_movie_trailer_link(video_hash) else: trailer_url = settings.BASE_KINOHOD shorten_url = botan.shorten_url( str(telegram_user_id) + trailer_url, settings.BOTAN_TOKEN, telegram_user_id if telegram_user_id else 0) if film.premiereDateRussia and film.premiereDateRussia > now: markup = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.TREILER, url=shorten_url), dict(text=settings.NEAREST_SEANCES, callback_data='/future{}'.format(movie_id)) ]]) else: markup = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.TREILER, url=shorten_url), dict(text=settings.CHOOSE_SEANCE, callback_data=( '{}{}num{}'.format(next_url, film.kinohod_id, settings.CINEMAS_TO_DISPLAY))), ]]) else: if film.premiereDateRussia and film.premiereDateRussia > now: markup = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.NEAREST_SEANCES, callback_data='/future{}'.format(movie_id)) ]]) else: markup = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.CHOOSE_SEANCE, callback_data=( '{}{}num{}'.format(next_url, film.kinohod_id, 20))) ]]) Annotation = namedtuple('Annotation', ['title', 'link']) if full: template = settings.JINJA_ENVIRONMENT.get_template( 'movies_info_full.md') actors = film.actors ann_o = Annotation(film.annotationFull, '') return template.render({ 'title': film.title, 'description': ann_o, 'duration': film.duration if film.duration else None, 'premier': (film.premiereDateRussia.strftime('%d.%m.%Y') if film.premiereDateRussia else None), 'sign_calendar': settings.SIGN_CALENDAR, 'age': film.ageRestriction if film.ageRestriction else None, 'sign_genre': settings.SIGN_GENRE, 'kinder': settings.SIGN_CHILD_AGE, 'sign_time': settings.SIGN_ALARM, 'genres': ', '.join([a.get().name.encode('utf-8') for a in film.genres]).decode('utf-8'), 'sign_actor': settings.SIGN_ACTOR, 'actors': ', '.join([a.get().name.encode('utf-8') for a in actors]).decode('utf-8') if actors else None, 'directors': ', '.join([a.get().name.encode('utf-8') for a in film.directors ]).decode('utf-8') if film.directors else None, 'sign_producer': settings.SIGN_PRODUCER, }), markup, movie_poster else: template = settings.JINJA_ENVIRONMENT.get_template('movies_info.md') actors = (film.actors[:3] if film.actors and len(film.actors) > 3 else film.actors) ann_o = Annotation( film.annotationShort, 'Подробнее: /fullinfo{}'.decode('utf-8').format(movie_id)) return template.render({ 'title': film.title, 'description': ann_o, 'sign_genre': settings.SIGN_GENRE, 'genres': ', '.join([a.get().name.encode('utf-8') for a in film.genres ]).decode('utf-8') if film.genres else None, 'sign_actor': settings.SIGN_ACTOR, 'actors': ', '.join( [a.get().name.encode('utf-8') for a in actors if a.get()]).decode('utf-8') if actors else None, 'directors': ', '.join([ a.get().name.encode('utf-8') for a in film.directors if a.get() ]).decode('utf-8') if film.directors else None, 'sign_producer': settings.SIGN_PRODUCER, }), markup, movie_poster
def test_add_movie(app): app.movie.create(Film(name="Test", year="1234", description="Goes here"))
def detect_cinema_seances(cinema_id, movie_id, day): if not isinstance(day, datetime): day = int(day) day_str = _day_of_seance(day) else: day_str = day.strftime('%d%m%Y') url = settings.URL_CINEMA_SEANCES.format(cinema_id, settings.KINOHOD_API_KEY, day_str) try: with contextlib.closing(urllib2.urlopen(url)) as hd: html_data = json.loads(hd.read()) except Exception as ex: import logging logging.debug(ex.message) return None, None CinemaSeances = namedtuple('CinemaSeances', ['tip', 'time', 'minPrice', 'id', 'format']) if html_data is None: return settings.NO_SEANCE, None place = ''.decode('utf-8') if isinstance(html_data, list) and len(html_data) > 0: place = html_data[0]['cinema']['title'] for info in html_data: if int(movie_id) != int(info['movie']['id']): continue seances = [] for s in info['schedules']: m_p = s['minPrice'] if s['minPrice'] else None s_f = None if s['formatName'] and len(s['formatName']) < 10: s_f = s['formatName'] if _calculate_is_onsale(s['startTime']): seances.append( CinemaSeances(settings.SIGN_TIP, s['time'], m_p, int(s['id']), s_f)) else: seances.append( CinemaSeances(settings.SIGN_TIP, s['time'], m_p, 0, s_f)) f = html_data[0]['movie'] premier = f.get('premiereDateRussia') if premier: premier = datetime.strptime(premier.split('T')[0], '%Y-%m-%d') if premier and premier > datetime.now(): markup = _construct_markup(cinema_id, movie_id, day, only_another=True) else: markup = _construct_markup(cinema_id, movie_id, day) template = settings.JINJA_ENVIRONMENT.get_template('cinema_seances.md') if day_str: day_str = day_str.decode('utf-8') day_str = '{}.{}.{}'.format(day_str[:2], day_str[2:4], day_str[4:]) else: day_str = '' return template.render({ 'title': info['movie']['title'], 'seances': seances, 'place': place, 'date': day_str }), markup cinema = Cinema.get_by_id(str(cinema_id)) film = Film.get_by_id(str(movie_id)) markup = _construct_markup(cinema_id, movie_id, day) day = day.strftime('%d.%m') if isinstance(day, datetime) else '' return settings.NO_FILM_SCHEDULE.format( film.title if film else '', day, cinema.title if cinema else ''), markup
def get_nearest_cinemas(bot, chat_id, number_of_cinemas, movie_id=None, next_url='/show'): # TODO: REWRITE THIS PEACE OF SHIT, PLEASE u = get_model(UserProfile, chat_id) if not u.location: bot.sendMessage(chat_id, settings.CANNOT_FIND_YOU) return None, None l = json.loads(u.location) city_id = detect_city_id_by_location(l) url = '{}&latitude={}&longitude={}&sort=distance&city={}'.format( settings.URL_CINEMAS.format(settings.KINOHOD_API_KEY), l.get('latitude'), l.get('longitude'), city_id) film = None if movie_id: film = Film.get_by_id(str(movie_id)) data = get_data(url) if not data: return settings.DONT_UNDERSTAND, None cinemas = [] template = settings.JINJA_ENVIRONMENT.get_template('cinema_where_film.md') film_cinemas = get_schedule(movie_id, date=None, city_id=city_id) if film_cinemas: film_cinema_ids = [str(fc['cinema']['id']) for fc in film_cinemas] else: return settings.DONT_UNDERSTAND, None right_border = number_of_cinemas for film_counter in xrange(number_of_cinemas - settings.CINEMA_TO_SHOW, right_border): if film_counter < len(data): cinema = data[film_counter] else: return (settings.NO_FILMS, InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.FIRST_THREE, callback_data=( '/nearest{}'.format(settings.CINEMA_TO_SHOW))) ]])) cinema_id = str(cinema.get('id')) cinema_title = cinema.get('shortTitle') # poor place because of long request # poor place because of double getter if film and cinema_id: if cinema_id not in film_cinema_ids: continue link = '{}{}m{}'.format(next_url, cinema_id, movie_id) else: link = '{}{}'.format(next_url, cinema_id) cinemas.append( settings.RowCinema(cinema_title, cinema.get('address'), cinema.get('mall'), link)) if film and len(cinemas) < 1: return get_cinemas_where_film(film, settings.CINEMAS_TO_DISPLAY, chat_id) if film: mark_up = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.MORE, callback_data='/nearest{}m{}'.format( number_of_cinemas + settings.CINEMA_TO_SHOW, movie_id)) ]]) else: mark_up = InlineKeyboardMarkup(inline_keyboard=[[ dict(text=settings.MORE, callback_data='/nearest{}'.format(number_of_cinemas + settings.CINEMA_TO_SHOW)) ]]) film_name = film.title if film else None return template.render({ 'film_name': film_name, 'seances': cinemas }), mark_up
def test_add_film(app): new_film = Film.unic_name() app.ensure_login_as(User.Admin()) app.add_film(new_film) assert app.is_film_created(new_film)
def test_add_film(app): app.ensure_logout() app.login(User.Admin()) assert app.is_logged_in() app.add(Film.AddFilm())
def get_seances(chat_id, movie_id, number_of_seances, date=datetime.now().strftime('%d%m%Y')): u = get_model(UserProfile, chat_id) f = Film.get_by_id(str(movie_id)) f_cinemas, city_id = detect_film_cinemas(chat_id, movie_id, date=date) if f and not f_cinemas: return settings.NO_FILM_SEANCE cinema_ids = [k['cinema']['id'] for k in f_cinemas] if u: l = json.loads(u.location) latitude, longitude = l['latitude'], l['longitude'] url = '{}?lat={}&long={}&sort=distance&cityId=1'.format( settings.URL_WIDGET_CINEMAS, latitude, longitude, ) seances = [] html_data = get_data(url) if not html_data: return settings.DONT_UNDERSTAND, None if 'data' not in html_data: return settings.CANNOT_FIND_SEANCE, None for info in html_data['data']: cinema_id = info.get('id') if str(cinema_id) not in cinema_ids: continue seances.append( settings.RowDist( settings.uncd(info['shortTitle']), info['distance'], '/c{}m{}'.format(cinema_id, movie_id) ) ) if len(seances) < 1: return settings.NO_FILM_SEANCE, None correct, n = False, settings.SEANCES_TO_DISPLAY while not correct: if len(seances) > number_of_seances: n = settings.SEANCES_TO_DISPLAY seances = seances[number_of_seances - n: number_of_seances] correct = True elif len(seances) > (number_of_seances - n): seances = seances[number_of_seances - n:] correct = True else: number_of_seances = n empty_data(html_data=html_data) mark_up = gen_markup(movie_id, number_of_seances) template = settings.JINJA_ENVIRONMENT.get_template( 'seances_distance.md' ) else: url = settings.URL_SEANCES.format( str(movie_id), settings.KINOHOD_API_KEY, (number_of_seances - settings.SEANCES_TO_DISPLAY), number_of_seances ) seances = [] html_data = get_data(url) if not html_data: return settings.DONT_UNDERSTAND, None for info in html_data: cinema_json = info.get('cinema') cinema_id = cinema_json.get('id') if str(cinema_id) not in cinema_ids: continue seances.append( settings.RowCinema( settings.uncd(cinema_json['shortTitle']), cinema_json.get('address'), cinema_json.get('mall'), '/c{}m{}'.format(cinema_id, info['movie']['id'])) ) empty_data(html_data=html_data) mark_up = gen_markup(movie_id, number_of_seances) template = settings.JINJA_ENVIRONMENT.get_template('seances.md') return template.render({ 'date': datetime.strptime(date, '%d%m%Y').strftime('%d.%m.%Y'), 'sign_point': settings.SIGN_POINT, 'sign_tip': settings.SIGN_TIP, 'seances': seances }), mark_up
def test_remove_film(app): app.ensure_logout() app.login(User.Admin()) assert app.is_logged_in() app.add(Film.RemoveFilm()) app.remove()
def display_seances_part(chat_id, text, movie_id, number_of_seances, date=datetime.now().strftime('%d%m%Y')): url = settings.URL_FULL_SEANCES.format( str(movie_id), settings.KINOHOD_API_KEY, date ) seances = [] f = Film.get_by_id(str(movie_id)) f_cinemas, city_id = detect_film_cinemas(chat_id, movie_id, date=date) if f and not f_cinemas: return settings.NO_FILM_SEANCE cinema_ids = [k['cinema']['id'] for k in f_cinemas] html_data = get_data(url) if not html_data: return settings.DONT_UNDERSTAND for info in html_data: cinema_json = info.get('cinema') cinema_id = cinema_json.get('id') if cinema_id not in cinema_ids: continue if (('shortTitle' in cinema_json and cinema_json['shortTitle'].find(text) > -1) or ('address' in info['cinema'] and cinema_json['address'].find(text) > -1) or ('subway_stations' in cinema_json and 'name' in cinema_json['subway_stations'] and cinema_json['subway_stations']['name'].find(text) > -1)): seances.append( settings.RowCinema( cinema_json['shortTitle'], cinema_json.get('address'), cinema_json.get('mall'), '/c{}m{}'.format(cinema_json['id'], info['movie']['id'])) ) empty_data(html_data=html_data) if len(seances) < 1: template = settings.JINJA_ENVIRONMENT.get_template('no_seances.md') return template.render({}) correct, n = False, settings.SEANCES_TO_DISPLAY while not correct: if len(seances) > number_of_seances: n = settings.SEANCES_TO_DISPLAY seances = seances[number_of_seances - n: number_of_seances] correct = True elif len(seances) > (number_of_seances - n): seances = seances[number_of_seances - n:] correct = True else: number_of_seances = n template = settings.JINJA_ENVIRONMENT.get_template('seances.md') return template.render({ 'date': datetime.strptime(date, '%d%m%Y').strftime('%d.%m.%Y'), 'sign_point': settings.SIGN_POINT, 'sign_tip': settings.SIGN_TIP, 'seances': seances })