Esempio n. 1
0
def search(query, limit):
    movie = Movie()
    s = movie.search(query)
    first_result = s[0]
    recommendations = movie.recommendations(first_result.id)
    recommendations = recommendations[:int(
        limit)] if recommendations >= limit else recommendations
    for recommendation in recommendations:
        print("%s (%s)" % (recommendation.title, recommendation.release_date))
Esempio n. 2
0
def get_recommend(parameters):
    movie = Movie()
    search = tmdb.Search()
    response = search.movie(query=parameters['movie_name'])
    idd = response['results'][0]['id']
    recommendations = movie.recommendations(idd)
    ans = ''
    for recommendation in recommendations:
        ans += (recommendation.title + "\n")
    return ans
def movie(name):
    movie = Movie()
    search = movie.search(name)
    for res in search:
        x = res.id
        print(x)
        break

    recommendations = movie.recommendations(movie_id=x)
    oh = []
    num = 0
    for some in recommendations:
        if num >= 6:
            break

        a = (some.title)
        b = (some.poster_path)
        c = (some.vote_average)
        d = (some.release_date)
        e = (some.vote_count)
        final_dict = {'name': a, 'link': b, 'vote': c, 'date': d, 'count': e}
        oh.append(final_dict)
        num = num + 1
    return oh
Esempio n. 4
0
class TMDbTests(unittest.TestCase):
    def setUp(self):
        self.tmdb = TMDb()
        self.tmdb.api_key = os.environ['TMDB_API_KEY']
        self.tmdb.language = 'en'
        self.tmdb.debug = True
        self.tmdb.wait_on_rate_limit = True
        self.movie = Movie()
        self.discover = Discover()
        self.tv = TV()
        self.person = Person()
        self.collection = Collection()
        self.company = Company()
        self.season = Season()

    def test_get_movie(self):
        movie = self.movie.details(111)
        self.assertIsNotNone(movie)
        self.assertEqual(movie.title, 'Scarface')
        self.assertEqual(movie.id, 111)
        self.assertTrue(hasattr(movie, 'title'))
        self.assertTrue(hasattr(movie, 'overview'))
        self.assertTrue(hasattr(movie, 'id'))

    def test_get_movie_reviews(self):
        search = self.movie.search("Mad Max")
        self.assertTrue(len(search) > 0)
        first = search[0]
        reviews = self.movie.reviews(first.id)
        self.assertTrue(len(reviews) > 0)
        for review in reviews:
            self.assertTrue(hasattr(review, 'id'))
            self.assertTrue(hasattr(review, 'content'))

    def test_get_movie_lists(self):
        lists = self.movie.lists(111)
        self.assertTrue(len(lists) > 0)
        self.assertTrue(hasattr(lists[0], 'description'))
        self.assertTrue(hasattr(lists[0], 'name'))

    def test_get_movie_videos(self):
        videos = self.movie.videos(111)
        self.assertTrue(len(videos) > 0)
        self.assertTrue(hasattr(videos[0], 'id'))

    def test_get_movie_recommendations(self):
        recs = self.movie.recommendations(111)
        self.assertTrue(len(recs) > 0)
        self.assertTrue(hasattr(recs[0], 'id'))

    def test_discover_movies(self):
        discover = self.discover.discover_movies({
            'primary_release_year': '2015',
            'with_genres': '28',
            'page': '1',
            'vote_average.gte': '8'

        })

        self.assertTrue(len(discover) > 0)
        self.assertTrue(hasattr(discover[0], 'id'))
        movie = discover[0]

        has_genre = False
        for genre_id in movie.genre_ids:
            if genre_id == 28:
                has_genre = True
        self.assertTrue(has_genre)

    def test_discover_tv_shows(self):
        discover = self.discover.discover_tv_shows({
            'with_genres': '16',
            'vote_average.gte': '8',
            'page': '1'
        })
        self.assertTrue(len(discover) > 0)
        self.assertTrue(hasattr(discover[0], 'id'))
        movie = discover[0]
        has_genre = False
        for genre_id in movie.genre_ids:
            if genre_id == 16:
                has_genre = True
        self.assertTrue(has_genre)

    def test_get_latest_movie(self):
        videos = self.movie.latest()
        self.assertIsNotNone(videos)
        self.assertTrue(hasattr(videos, 'id'))

    def test_now_playing(self):
        now_playing = self.movie.now_playing()
        self.assertTrue(len(now_playing) > 0)
        self.assertTrue(hasattr(now_playing[0], 'id'))

    def test_top_rated(self):
        top_rated = self.movie.top_rated()
        self.assertTrue(len(top_rated) > 0)
        self.assertTrue(hasattr(top_rated[0], 'id'))

    def test_upcoming(self):
        upcoming = self.movie.upcoming()
        self.assertTrue(len(upcoming) > 0)
        self.assertTrue(hasattr(upcoming[0], 'id'))

    def test_popular(self):
        popular = self.movie.popular()
        self.assertTrue(len(popular) > 0)
        self.assertTrue(hasattr(popular[0], 'id'))

    def test_search(self):
        search = self.movie.search('Mad Max')
        self.assertTrue(len(search) > 0)
        self.assertTrue(hasattr(search[0], 'id'))

    def test_similar(self):
        similar = self.movie.similar(111)
        self.assertTrue(len(similar) > 0)
        self.assertTrue(hasattr(similar[0], 'id'))

    def test_get_tv_show(self):
        show = self.tv.details(12)
        self.assertIsNotNone(show)
        self.assertTrue(hasattr(show, 'id'))

    def test_get_latest_tv_show(self):
        latest_tv = self.tv.latest()
        self.assertIsNotNone(latest_tv)
        self.assertTrue(hasattr(latest_tv, 'id'))

    def test_search_tv(self):
        search_tv = self.tv.search('Sunny')
        self.assertTrue(len(search_tv) > 0)
        self.assertTrue(hasattr(search_tv[0], 'id'))

    def test_popular_shows(self):
        popular = self.tv.popular()
        self.assertTrue(len(popular) > 0)
        self.assertTrue(hasattr(popular[0], 'id'))

    def test_top_rated_shows(self):
        top_rated = self.tv.top_rated()
        self.assertTrue(len(top_rated) > 0)
        self.assertTrue(hasattr(top_rated[0], 'id'))

    def test_get_person(self):
        person = self.person.details(234)
        self.assertIsNotNone(person)
        self.assertTrue(hasattr(person, 'id'))

    def test_search_person(self):
        search_person = self.person.search('Bryan')
        self.assertTrue(len(search_person) > 0)
        self.assertTrue(hasattr(search_person[0], 'id'))

    def test_collection_details(self):
        c = Collection()
        details = c.details(10)
        self.assertEqual(details.name, 'Star Wars Collection')
        self.assertEqual(details.id, 10)
        self.assertTrue(hasattr(details, 'overview'))
        self.assertTrue(hasattr(details, 'poster_path'))

    def test_collection_images(self):
        c = Collection()
        images = c.images(10)
        self.assertTrue(hasattr(images, 'backdrops'))
        self.assertTrue(hasattr(images, 'posters'))

    def test_popular_people(self):
        popular = self.person.popular()
        self.assertTrue(len(popular) > 0)
        first = popular[0]
        self.assertTrue(hasattr(first, 'name'))
        self.assertTrue(hasattr(first, 'known_for'))

    def test_latest_person(self):
        latest_person = self.person.latest()
        self.assertIsNotNone(latest_person)
        self.assertTrue(hasattr(latest_person, 'name'))
        self.assertTrue(hasattr(latest_person, 'id'))

    def test_person_images(self):
        images = self.person.images(11)
        self.assertIsNotNone(images)
        self.assertTrue(hasattr(images, 'profiles'))
        self.assertTrue(hasattr(images, 'id'))

    def test_company_details(self):
        c = self.company.details(1)
        self.assertTrue(hasattr(c, 'name'))
        self.assertEqual(c.name, 'Lucasfilm')

    def test_company_movies(self):
        company = self.company.movies(1)
        self.assertTrue(len(company) > 0)
        first = company[0]
        self.assertTrue(hasattr(first, 'title'))
        self.assertTrue(hasattr(first, 'overview'))

    def test_config(self):
        config = Configuration()
        info = config.info()
        self.assertIsNotNone(info)
        self.assertTrue(hasattr(info, 'images'))

    def test_genres(self):
        genres = Genre()
        movie_genres = genres.movie_list()
        self.assertIsNotNone(movie_genres)
        tv_genres = genres.tv_list()
        self.assertIsNotNone(tv_genres)

    def test_season(self):
        s = self.season.details(1418, 1)
        self.assertIsNotNone(s)
        self.assertEqual(s.name, 'Season 1')
        self.assertEqual(s.id, 3738)
        self.assertTrue(hasattr(s, 'episodes'))
        self.assertTrue(hasattr(s, 'overview'))
        self.assertTrue(hasattr(s, 'id'))

    def test_get_season_changes(self):
        s = self.season.changes(1418, 1)
        self.assertIsNotNone(s)

    def test_get_season_external_ids(self):
        s = self.season.external_ids(1418, 1)
        self.assertIsNotNone(s)
        self.assertIsNotNone(s['tvdb_id'])

    def test_get_season_videos(self):
        s = self.season.videos(1418, 1)

    def test_get_season_images(self):
        s = self.season.images(1418, 1)
        for l in s:
            self.assertIsNotNone(l.width)
            self.assertIsNotNone(l.height)

    def test_get_season_credits(self):
        s = self.season.credits(1418, 1)
        for c in s:
            self.assertIsNotNone(c.name)
            self.assertIsNotNone(c.character)

    def test_get_movie_by_external_id(self):
        ex = self.movie.external(external_id="tt8155288", external_source="imdb_id")
        res = ex['movie_results'][0]
        self.assertTrue(res['title'] == "Happy Death Day 2U")
Esempio n. 5
0
app = Flask(__name__)

tmdb = TMDb()
tmdb.api_key = '0f90dc240d06fa41a1a68cbc6abd44af'

movie = Movie()
popular_pelis = movie.popular()

#redis
#r = redis.Redis(host='localhost', port=6379, db=0)
#r.set('foo','bar')
#r.get('foo')

##prueba
recomended_pelis = movie.recommendations(movie_id=111)

lista_recomended_titulos = []
lista_recomended_release_date = []
lista_recomended_popularity = []
lista_recomended_imagenes = []
for r in recomended_pelis:
    titulos = str(r.title)
    release_date = str(r.release_date)
    popularity = str(r.popularity)
    imagenes = str(r.poster_path)

    lista_recomended_titulos.append(titulos)
    lista_recomended_release_date.append(release_date)
    lista_recomended_popularity.append(popularity)
    lista_recomended_imagenes.append(imagenes)
Esempio n. 6
0
class TMDbTests(unittest.TestCase):
    def setUp(self):
        self.tmdb = TMDb()
        self.tmdb.api_key = os.environ["TMDB_API_KEY"]
        self.tmdb.language = "en"
        self.tmdb.debug = True
        self.tmdb.wait_on_rate_limit = True
        self.movie = Movie()
        self.discover = Discover()
        self.tv = TV()
        self.person = Person()
        self.collection = Collection()
        self.company = Company()
        self.season = Season()
        self.list = List()

    def test_get_tv_keywords(self):
        keywords = self.tv.keywords(1396)
        self.assertGreater(len(keywords), 0)

    def test_get_tv_reviews(self):
        reviews = self.tv.reviews(1396)
        self.assertGreater(len(reviews), 0)

    def test_get_movie_repr(self):
        search = self.movie.search("Mad Max")
        for results in search:
            print(results)

    def test_get_tv_show_repr(self):
        search_tv = self.tv.search("Breaking Bad")
        for results in search_tv:
            print(results)

    def test_get_movie(self):
        movie = self.movie.details(111)
        self.assertIsNotNone(movie)
        self.assertEqual(movie.title, "Scarface")
        self.assertEqual(movie.id, 111)
        self.assertTrue(hasattr(movie, "title"))
        self.assertTrue(hasattr(movie, "overview"))
        self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_reviews(self):
        search = self.movie.search("Mad Max")
        self.assertTrue(len(search) > 0)
        first = search[0]
        reviews = self.movie.reviews(first.id)
        self.assertTrue(len(reviews) > 0)
        for review in reviews:
            self.assertTrue(hasattr(review, "id"))
            self.assertTrue(hasattr(review, "content"))

    def test_get_movie_lists(self):
        lists = self.movie.lists(111)
        self.assertTrue(len(lists) > 0)
        self.assertTrue(hasattr(lists[0], "description"))
        self.assertTrue(hasattr(lists[0], "name"))

    def test_get_movie_credits(self):
        credits = self.movie.credits(111)
        print(credits)
        self.assertIsNotNone(credits)

    def test_get_movie_images(self):
        images = self.movie.images(111)
        print(images)
        self.assertIsNotNone(images)

    def test_get_movie_videos(self):
        videos = self.movie.videos(111)
        self.assertTrue(len(videos) > 0)
        self.assertTrue(hasattr(videos[0], "id"))

    def test_get_movie_recommendations(self):
        recs = self.movie.recommendations(111)
        self.assertTrue(len(recs) > 0)
        self.assertTrue(hasattr(recs[0], "id"))

    def test_discover_movies(self):
        discover = self.discover.discover_movies({
            "primary_release_year": "2015",
            "with_genres": "28",
            "page": "1",
            "vote_average.gte": "8",
        })

        self.assertTrue(len(discover) > 0)
        self.assertTrue(hasattr(discover[0], "id"))
        movie = discover[0]

        has_genre = False
        for genre_id in movie.genre_ids:
            if genre_id == 28:
                has_genre = True
        self.assertTrue(has_genre)

    def test_discover_tv_shows(self):
        discover = self.discover.discover_tv_shows({
            "with_genres": "16",
            "vote_average.gte": "8",
            "page": "1"
        })
        self.assertTrue(len(discover) > 0)
        self.assertTrue(hasattr(discover[0], "id"))
        movie = discover[0]
        has_genre = False
        for genre_id in movie.genre_ids:
            if genre_id == 16:
                has_genre = True
        self.assertTrue(has_genre)

    def test_get_latest_movie(self):
        videos = self.movie.latest()
        self.assertIsNotNone(videos)
        self.assertTrue(hasattr(videos, "id"))

    def test_now_playing(self):
        now_playing = self.movie.now_playing()
        self.assertTrue(len(now_playing) > 0)
        self.assertTrue(hasattr(now_playing[0], "id"))

    def test_top_rated(self):
        top_rated = self.movie.top_rated()
        self.assertTrue(len(top_rated) > 0)
        self.assertTrue(hasattr(top_rated[0], "id"))

    def test_upcoming(self):
        upcoming = self.movie.upcoming()
        self.assertTrue(len(upcoming) > 0)
        self.assertTrue(hasattr(upcoming[0], "id"))

    def test_popular(self):
        popular = self.movie.popular()
        self.assertTrue(len(popular) > 0)
        self.assertTrue(hasattr(popular[0], "id"))

    def test_search(self):
        search = self.movie.search("Mad Max")
        self.assertTrue(len(search) > 0)
        self.assertTrue(hasattr(search[0], "id"))

    def test_similar(self):
        similar = self.movie.similar(111)
        self.assertTrue(len(similar) > 0)
        self.assertTrue(hasattr(similar[0], "id"))

    def test_get_tv_show(self):
        show = self.tv.details(12)
        self.assertIsNotNone(show)
        self.assertTrue(hasattr(show, "id"))

    def test_on_the_air(self):
        show = self.tv.on_the_air()
        self.assertTrue(len(show) > 0)

    def test_airing_today(self):
        show = self.tv.on_the_air()
        self.assertTrue(len(show) > 0)

    def test_tv_videos(self):
        show = self.tv.videos(1396)
        self.assertTrue(len(show) > 0)

    def test_tv_recommendations(self):
        show = self.tv.recommendations(1396)
        self.assertTrue(len(show) > 0)

    def test_external_ids(self):
        show = self.tv.external_ids(1776)
        self.assertEqual(show["imdb_id"], "tt0488262")

    def test_get_latest_tv_show(self):
        latest_tv = self.tv.latest()
        self.assertIsNotNone(latest_tv)
        self.assertTrue(hasattr(latest_tv, "id"))

    def test_search_tv(self):
        search_tv = self.tv.search("Sunny")
        self.assertTrue(len(search_tv) > 0)
        self.assertTrue(hasattr(search_tv[0], "id"))

    def test_popular_shows(self):
        popular = self.tv.popular()
        self.assertTrue(len(popular) > 0)
        self.assertTrue(hasattr(popular[0], "id"))

    def test_top_rated_shows(self):
        top_rated = self.tv.top_rated()
        self.assertTrue(len(top_rated) > 0)
        self.assertTrue(hasattr(top_rated[0], "id"))

    def test_get_person(self):
        person = self.person.details(234)
        self.assertIsNotNone(person)
        self.assertTrue(hasattr(person, "id"))

    def test_search_person(self):
        search_person = self.person.search("Bryan")
        self.assertTrue(len(search_person) > 0)
        self.assertTrue(hasattr(search_person[0], "id"))

    def test_collection_details(self):
        c = Collection()
        details = c.details(10)
        self.assertEqual(details.name, "Star Wars Collection")
        self.assertEqual(details.id, 10)
        self.assertTrue(hasattr(details, "overview"))
        self.assertTrue(hasattr(details, "poster_path"))

    def test_collection_images(self):
        c = Collection()
        images = c.images(10)
        self.assertTrue(hasattr(images, "backdrops"))
        self.assertTrue(hasattr(images, "posters"))

    def test_popular_people(self):
        popular = self.person.popular()
        self.assertTrue(len(popular) > 0)
        first = popular[0]
        self.assertTrue(hasattr(first, "name"))
        self.assertTrue(hasattr(first, "known_for"))

    def test_latest_person(self):
        latest_person = self.person.latest()
        self.assertIsNotNone(latest_person)
        self.assertTrue(hasattr(latest_person, "name"))
        self.assertTrue(hasattr(latest_person, "id"))

    def test_person_images(self):
        images = self.person.images(11)
        self.assertIsNotNone(images)
        self.assertTrue(hasattr(images, "profiles"))
        self.assertTrue(hasattr(images, "id"))

    def test_company_details(self):
        c = self.company.details(1)
        self.assertTrue(hasattr(c, "name"))
        self.assertEqual(c.name, "Lucasfilm Ltd.")

    def test_company_movies(self):
        company = self.company.movies(1)
        self.assertTrue(len(company) > 0)
        first = company[0]
        self.assertTrue(hasattr(first, "title"))
        self.assertTrue(hasattr(first, "overview"))

    def test_config(self):
        config = Configuration()
        info = config.info()
        self.assertIsNotNone(info)
        self.assertTrue(hasattr(info, "images"))

    def test_genres(self):
        genres = Genre()
        movie_genres = genres.movie_list()
        self.assertIsNotNone(movie_genres)
        tv_genres = genres.tv_list()
        self.assertIsNotNone(tv_genres)

    def test_season(self):
        s = self.season.details(1418, 1)
        self.assertIsNotNone(s)
        self.assertEqual(s.name, "Season 1")
        self.assertEqual(s.id, 3738)
        self.assertTrue(hasattr(s, "episodes"))
        self.assertTrue(hasattr(s, "overview"))
        self.assertTrue(hasattr(s, "id"))

    def test_get_season_changes(self):
        s = self.season.changes(1418)
        self.assertIsNotNone(s)

    def test_get_season_external_ids(self):
        s = self.season.external_ids(1418, 1)
        self.assertIsNotNone(s)
        self.assertIsNotNone(s["tvdb_id"])

    def test_get_season_videos(self):
        s = self.season.videos(1418, 1)

    def test_get_season_images(self):
        s = self.season.images(1418, 1)
        for l in s:
            self.assertIsNotNone(l.width)
            self.assertIsNotNone(l.height)

    def test_get_season_credits(self):
        s = self.season.credits(1418, 1)
        for c in s:
            self.assertIsNotNone(c.name)
            self.assertIsNotNone(c.character)

    def test_get_movie_by_external_id(self):
        ex = self.movie.external(external_id="tt8155288",
                                 external_source="imdb_id")
        res = ex["movie_results"][0]
        self.assertTrue(res["title"] == "Happy Death Day 2U")

    def test_get_list(self):
        list = self.list.details(list_id="112870")
        self.assertTrue(len(list) > 10)
        self.assertTrue(hasattr(list[0], "id"))
        self.assertTrue(hasattr(list[0], "title"))

    def test_get_certifications(self):
        certifications = Certification()
        movie_certifications = certifications.movie_list()
        self.assertIsNotNone(movie_certifications)
        tv_certifications = certifications.tv_list()
        self.assertIsNotNone(tv_certifications)
Esempio n. 7
0
from tmdbv3api import TMDb
tmdb = TMDb()
tmdb.api_key = '166d285b00c7c31afd5fc98b33fec846'

tmdb.language = 'en'
tmdb.debug = True

from tmdbv3api import Movie
movie = Movie()

recommendations = movie.recommendations(movie_id=109)

for recommendation in recommendations:
    print(recommendation.title)
Esempio n. 8
0
def process_text(input, intent, request=None):
    try:
        if intent == 'word':
            open_application('word')
        if intent == 'firefox':
            open_application('firefox')
        if intent == 'youtube':
            assistant_speaks('Sure. Tell me what do you want to search for')
            ans = get_audio()
            result = parse_stopwords(ans)
            search_web('youtube ' + result)
        if intent == 'knowledge':
            if 'about' in input:
                parse_text(input, 'about')
            if 'what is' in input:
                parse_text(input, 'is')
            if 'who was' in input:
                parse_text(input, 'was')
        if intent == 'web_search':
            if 'about' in input:
                ans = input
                indx = ans.split().index('about')
                query = ans.split()[indx + 1:]
                string_query = ' '.join(query)
                result = parse_stopwords(string_query)
                search_web('google ' + result)
            if 'for' in input:
                ans = input
                indx = ans.split().index('for')
                query = ans.split()[indx + 1:]
                string_query = ' '.join(query)
                result = parse_stopwords(string_query)
                search_web('google ' + result)
            assistant_speaks('Going back to the main interface')
        movie_list_intents = ['movie', 'horror', 'action', 'comedy', 'popular', 'thriller']
        if intent in movie_list_intents:
            from tmdbv3api import Movie

            movie = Movie()
            discover = Discover()
            if intent == 'popular':
                pop_movie = discover.discover_movies({
                    'sort_by': 'popularity.desc'
                })
                assistant_speaks("The most popular 5 movies are the following")
                pop_movies = ", ".join(str(x) for x in pop_movie[0:5])
                assistant_speaks(pop_movies)
            if intent == 'horror':
                parse_movies(27, discover, movie, 'horror')
            if intent == 'action':
                parse_movies(28, discover, movie, 'action')
            if intent == 'comedy':
                parse_movies(35, discover, movie, 'comedy')
            if intent == 'thriller':
                parse_movies(53, discover, movie, 'thriller')
            if intent == 'movie':
                assistant_speaks('Do you want a movie recommendation based on your favorite movie?')
                ans = get_audio()
                if 'yes' in ans:
                    try:
                        pacient = Pacient.objects.get(user=request.user)
                    except:
                        assistant_speaks('it looks like you have not discussed that with me. '
                                         'please enter discussion module first')
                    pac_details = PacientDetails.objects.get(pacient=pacient)
                    fav_movie = pac_details.fav_movie
                    search_movie = movie.search(fav_movie)
                    assistant_speaks('I will read top three recommended movies based on your favorite movie')
                    res = search_movie[0]
                    recommendations = movie.recommendations(movie_id=res.id)
                    cnt = 0
                    for recommendation in recommendations:
                        if cnt >= 3:
                            break
                        else:
                            assistant_speaks(recommendation.title)
                            assistant_speaks(recommendation.overview)
                        cnt += 1

                    assistant_speaks('Exiting movie module')
                else:
                    assistant_speaks(
                        'I can give you the top movies based on a genre. Just tell me what are you looking for')
                    ans = get_audio()
                    res, ints = chatbot_response(ans)
                    process_text(ans, ints)

        pacient = Pacient.objects.get(user=request.user)
        pac_pars = PacientParsing.objects.get(pacient=pacient)
        if intent == 'event':
            from googleapiclient.discovery import build
            from google_auth_oauthlib.flow import InstalledAppFlow
            scopes = ['https://www.googleapis.com/auth/calendar']
            flow = InstalledAppFlow.from_client_secrets_file("client_secret.json", scopes=scopes)
            credentials = flow.run_console()
            pickle.dump(credentials, open("token.pkl", "wb"))
            credentials = pickle.load(open("token.pkl", "rb"))
            service = build("calendar", "v3", credentials=credentials)

            calendarlist = service.calendarList().list().execute()
            calendar_id = calendarlist['items'][0]['id']
            result = service.events().list(calendarId=calendar_id, timeZone="Europe/Bucharest").execute()

            timp_event = get_audio()

            assistant_speaks("What about the name of the event?")
            name = get_audio()

            assistant_speaks("would you like to add a description?")
            ans = get_audio()
            sub_resp, sub_intent = chatbot_response(ans)
            if sub_intent == 'yes':
                assistant_speaks("please tell me the description")
                desc = get_audio()
                assistant_speaks("should i add a location too?")
                ans = get_audio()
                sub_resp, sub_intent = chatbot_response(ans)
                if sub_intent == 'yes':
                    assistant_speaks("Go ahead, tell me the location")
                    location = get_audio()
                    create_event(service, timp_event, name, 1, desc, location)
                elif sub_intent == 'no':
                    create_event(service, timp_event, name, 1, desc)
            elif sub_intent == 'no':
                create_event(service, timp_event, name)
            assistant_speaks('Event ' + name + ' created.')
            assistant_speaks('Exiting event module')
        if intent == 'web':
            ans = get_audio()
            result = parse_stopwords(ans)
            search_web('google ' + result)
            assistant_speaks('Exiting web module')
        if intent == 'discussion':
            assistant_speaks('Is there a certain topic you would like to discuss?')
            ans = get_audio()
            # print(ans)
            sub_resp, sub_intent = chatbot_response(ans)
            # print(sub_intent)
            if sub_intent == 'no':
                assistant_speaks('Then how about you tell me more about yourself?')
                try:
                    pac_details = PacientDetails.objects.get(pacient=pacient)
                except PacientDetails.DoesNotExist:
                    pac_details = PacientDetails.objects.create(pacient=pacient)
                if pac_details.fav_activity == '':
                    assistant_speaks('Tell me your favorite activity')
                    ans = get_audio()
                    if "don't" not in ans or 'no' not in ans:
                        ans = parse_details(ans)
                        # print(ans)
                        pac_details.fav_activity = ans
                        pac_details.save()
                if pac_details.fav_movie == '':
                    assistant_speaks('what about your favorite movie?')
                    ans = get_audio()
                    if "don't" not in ans or 'no' not in ans:
                        ans = parse_details(ans)
                        pac_details.fav_movie = ans
                        pac_details.save()
                if pac_details.fav_game == '':
                    assistant_speaks('Tell me your favorite game')
                    ans = get_audio()
                    if "don't" not in ans or 'no' not in ans:
                        ans = parse_details(ans)
                        pac_details.fav_game = ans
                        pac_details.save()
                if pac_details.fav_passion == '':
                    assistant_speaks('Do you have a favorite passion?')
                    ans = get_audio()
                    if "don't" not in ans or 'no' not in ans:
                        ans = parse_details(ans)
                        pac_details.fav_passion = ans
                        pac_details.save()
                if pac_details.fav_song == '':
                    assistant_speaks('What is your favorite song?')
                    ans = get_audio()
                    if "don't" not in ans or 'no' not in ans:
                        ans = parse_details(ans)
                        pac_details.fav_song = ans
                        pac_details.save()
                if pac_details.fav_book == '':
                    assistant_speaks('And your favorite book is?')
                    ans = get_audio()
                    if "don't" not in ans or 'no' not in ans:
                        ans = parse_details(ans)
                        pac_details.fav_book = ans
                        pac_details.save()
                assistant_speaks("How was your day so far? When you have finished talking, please say that's it")
                r = sr.Recognizer()
                list = []
                happy_list = ['That sounds great !', 'Wow, I am glad for you', 'Good job!', 'This sounds awesome']
                neutral_list = ['Okay, continue', 'Understood', 'What next?', 'Is there something more?']
                sad_list = ['What is the specific reason that made you feel this way? Please keep it short',
                            'Can you please tell me what is the root of the problem? Please keep it short',
                            'what disturbed you that much? Please keep it short']
                with sr.Microphone() as source:
                    while (1):
                        try:
                            print('Listening to your day: ')
                            audio = r.listen(source)
                            text = r.recognize_google(audio, language='en-US')
                            blob1 = TextBlob(text)
                            blob1 = blob1.correct()
                            text = text.lower()
                            print(format(blob1.sentiment))
                            if "that's it" in text:
                                break
                            if blob1.polarity < 0:
                                assistant_speaks(random.choice(sad_list))
                                motiv = get_audio_simple()
                                pac_pars._negative_problems += motiv + '\n'
                                pac_pars.contor_mesaje += 1
                                if pac_pars.contor_mesaje % 3 == 0:
                                    pac_pars.contor_mesaje = 0
                                    send_mail(
                                        'Mesaj informare pacient ' + str(pacient),
                                        'Urmatoarele probleme par sa-l afecteze pe pacient: ' + pac_pars._negative_problems,
                                        '*****@*****.**',
                                        ['*****@*****.**'],
                                        fail_silently=False,
                                    )
                                list.append(motiv)
                                pac_pars.save()
                                assistant_speaks('Sorry to hear that, please continue')
                            if blob1.polarity > 0.5:
                                assistant_speaks(random.choice(happy_list))
                            elif blob1.polarity <= 0.5 and blob1.polarity >= 0:
                                assistant_speaks(random.choice(neutral_list))
                        except:
                            continue

                motiv = random.choice(list)
                research_later = "what+to+do+when+" + motiv
                ua = UserAgent()
                google_url = "https://www.google.com/search?q=" + research_later
                response = requests.get(google_url, {"User-Agent": ua.random})
                soup = BeautifulSoup(response.text, "html.parser")
                result_div = soup.find_all('div', attrs={'class': 'ZINbbc'})

                links = []
                titles = []
                descriptions = []
                for r in result_div:
                    # Checks if each element is present, else, raise exception
                    try:
                        link = r.find('a', href=True)
                        title = r.find('div', attrs={'class': 'vvjwJb'}).get_text()
                        description = r.find('div', attrs={'class': 's3v9rd'}).get_text()

                        # Check to make sure everything is present before appending
                        if link != '' and title != '' and description != '':
                            links.append(link['href'])
                            titles.append(title)
                            descriptions.append(description)
                    # Next loop if one element is not present
                    except:
                        continue
                to_remove = []
                clean_links = []
                for i, l in enumerate(links):
                    clean = re.search('\/url\?q\=(.*)\&sa', l)

                    # Anything that doesn't fit the above pattern will be removed
                    if clean is None:
                        to_remove.append(i)
                        continue
                    clean_links.append(clean.group(1))
                # Remove the corresponding titles & descriptions
                # for x in to_remove:
                #     print(titles[x])
                #     print(descriptions[x])
                #     del titles[x]
                #     del descriptions[x]
                random_seed = random.randint(0, 3)
                print('rand_seed: ')
                print(random_seed)
                print('titles: ' + str(len(titles)))
                print('links: ' + str(len(clean_links)))
                assistant_speaks("I have found something regarding the problems you have just told me")
                assistant_speaks("The article title is called")
                assistant_speaks(titles[random_seed])
                assistant_speaks("Do you want me to open the link for you?")
                ans = get_audio()
                sub_resp, sub_intent = chatbot_response(ans)
                if sub_intent == 'yes':
                    driver = webdriver.Firefox()
                    driver.implicitly_wait(1)
                    driver.maximize_window()
                    driver.get(clean_links[random_seed])
                    assistant_speaks('I have opened the browser for you. Exiting discussion module')
                else:
                    assistant_speaks('Exiting discussion module')
                    return
            elif sub_intent == 'yes':
                assistant_speaks('Tell me what do you want to discuss.')
                ans = get_audio()
                res, intent = chatbot_response(ans)
                process_text(ans, intent, request)

        if intent == 'news':
            assistant_speaks("Would you like the news on a specific subject?")
            ans = get_audio()
            newsapi = NewsApiClient(api_key='b71542370a6247d493860e6b01d0d713')
            sub_resp, sub_intent = chatbot_response(ans)
            if sub_intent == 'yes':
                assistant_speaks('What would you like me to search for? Please be as specific as you can.')
                ans = get_audio()
                data = newsapi.get_everything(q=ans, language='en', page_size=5)
                articles = data['articles']
                assistant_speaks(
                    'You could choose one article by saying stop when i finish reading the headline. To continue '
                    'reading the headlines, just say continue. I found the following articles: ')
                for article in articles:
                    title = article['title']
                    url = article['url']
                    content = article['content']
                    assistant_speaks(title)
                    ans = get_audio()
                    if 'continue' in ans:
                        continue
                    elif 'stop' in ans:
                        assistant_speaks('I will read the article content')
                        assistant_speaks(content)
                        assistant_speaks(
                            'I can open the webpage which contains the article source. Do you want me to do that? ')
                        ans = get_audio()
                        sub_resp, sub_intent = chatbot_response(ans)
                        if sub_intent == 'yes':
                            driver = webdriver.Firefox()
                            driver.implicitly_wait(1)
                            driver.maximize_window()
                            driver.get(url)
                            r = sr.Recognizer()
                            assistant_speaks(
                                'I have opened your browser. To resume the articles read, just say resume. '
                                'If you want me to stop, just say stop')
                            with sr.Microphone() as source:
                                while (1):
                                    print('Listening ...')
                                    audio = r.listen(source)
                                    try:
                                        text = r.recognize_google(audio, language='en-US')
                                        if 'resume' in text:
                                            break
                                        elif 'stop' in text:
                                            return
                                    except:
                                        continue
                        elif sub_intent == 'no':
                            assistant_speaks('would you like me to continue reading the next articles?')
                            ans = get_audio()
                            sub_resp, sub_intent = chatbot_response(ans)
                            if sub_intent == 'yes':
                                continue
                            elif sub_intent == 'no':
                                assistant_speaks('If you want to find out more, just let me know. Exiting news module')
                                break
            elif sub_intent == 'no':
                assistant_speaks('Alright, i am going to search for the top headlines')
                url = ('http://newsapi.org/v2/top-headlines?'
                       'country=us&'
                       'apiKey=b71542370a6247d493860e6b01d0d713')
                response = requests.get(url).json()
                articles = response['articles']
                assistant_speaks(
                    'Say stop after I finish reading the headline to tell you its content. To continue reading '
                    'the headlines, just say continue. I found the following articles: ')
                for article in articles:
                    title = article['title']
                    url = article['url']
                    content = article['content']
                    assistant_speaks(title)
                    ans = get_audio()
                    if 'continue' in ans:
                        continue
                    elif 'stop' in ans:
                        assistant_speaks('I will read the article content')
                        assistant_speaks(content)
                        assistant_speaks('I can open the webpage which contains the article source. Do you want me'
                                         ' to do that? ')
                        ans = get_audio()
                        sub_resp, sub_intent = chatbot_response(ans)
                        if sub_intent == 'yes':
                            driver = webdriver.Firefox()
                            driver.implicitly_wait(1)
                            driver.maximize_window()
                            driver.get(url)
                        elif sub_intent == 'no':
                            assistant_speaks('would you like me to continue reading the next articles?')
                            ans = get_audio()
                            sub_resp, sub_intent = chatbot_response(ans)
                            if sub_intent == 'yes':
                                return
                            elif sub_intent == 'no':
                                assistant_speaks('If you want to find out more, just let me know. Exiting news module')
                                break
                    elif 'exit' in ans:
                        break
    except Exception as e:
        print(e)
        assistant_speaks("I don't understand, Can you please repeat?")
        ans = get_audio()
Esempio n. 9
0
class TMDbTests(unittest.TestCase):
    def setUp(self):
        self.tmdb = TMDb()
        self.tmdb.api_key = os.environ['TMDB_API_KEY']
        self.tmdb.language = 'en'
        self.tmdb.debug = True
        self.tmdb.wait_on_rate_limit = True
        self.movie = Movie()
        self.discover = Discover()
        self.tv = TV()
        self.person = Person()
        self.collection = Collection()
        self.company = Company()
        self.season = Season()
        self.list = List()

    def test_get_tv_keywords(self):
        keywords = self.tv.keywords(1396)
        self.assertGreater(len(keywords), 0)

    def test_get_tv_reviews(self):
        reviews = self.tv.reviews(1396)
        self.assertGreater(len(reviews), 0)

    def test_get_movie_repr(self):
        search = self.movie.search("Mad Max")
        for results in search:
            print(results)

    def test_get_tv_show_repr(self):
        search_tv = self.tv.search('Breaking Bad')
        for results in search_tv:
            print(results)

    def test_get_movie(self):
        movie = self.movie.details(111)
        self.assertIsNotNone(movie)
        self.assertEqual(movie['title'], 'Scarface')
        self.assertEqual(movie['id'], 111)
        self.assertTrue('title' in  movie)
        self.assertTrue('overview' in  movie)
        self.assertTrue('id' in  movie)

    def test_get_movie_reviews(self):
        search = self.movie.search("Mad Max")
        self.assertTrue(len(search) > 0)
        first = search[0]
        reviews = self.movie.reviews(first.id)
        self.assertTrue(len(reviews) > 0)
        for review in reviews:
            self.assertTrue('id' in review))
            self.assertTrue('content' in review))

    def test_get_movie_lists(self):
        lists = self.movie.lists(111)
        self.assertTrue(len(lists) > 0)
        self.assertTrue(hasattr(lists[0], 'description'))
        self.assertTrue(hasattr(lists[0], 'name'))

    def test_get_movie_credits(self):
        credits = self.movie.credits(111)
        print(credits)
        self.assertIsNotNone(credits)

    def test_get_movie_images(self):
        images = self.movie.images(111)
        print(images)
        self.assertIsNotNone(images)

    def test_get_movie_videos(self):
        videos = self.movie.videos(111)
        self.assertTrue(len(videos) > 0)
        self.assertTrue(hasattr(videos[0], 'id'))

    def test_get_movie_recommendations(self):
        recs = self.movie.recommendations(111)
        self.assertTrue(len(recs) > 0)
        self.assertTrue(hasattr(recs[0], 'id'))

    def test_discover_movies(self):
        discover = self.discover.discover_movies({
            'primary_release_year': '2015',
            'with_genres': '28',
            'page': '1',
            'vote_average.gte': '8'

        })
Esempio n. 10
0
def callback_inline(call):
    if call.message:
        if call.data == "emo1":
            bot.answer_callback_query(callback_query_id=call.id,
                                      show_alert=False,
                                      text="Thanks a million:)")
    if call.message:
        if call.data == "emo2":
            bot.answer_callback_query(callback_query_id=call.id,
                                      show_alert=False,
                                      text="Thanks a million:)")


#def film_part(call):

    if call.message:
        if call.data == "suggested":
            bot.send_message(call.message.chat.id, "Please wait...")
            sleep(3)
            movie = Movie()
            recommendations = movie.recommendations(movie_id=111)
            for recommendation in recommendations:
                bot.send_message(call.message.chat.id,
                                 "Film name - " + recommendation.title)
                sleep(1)
                bot.send_message(call.message.chat.id,
                                 "Overwiew - " + recommendation.overview)

    if call.message:
        if call.data == "popularr":
            bot.send_message(call.message.chat.id, "Please wait...")
            #movie = Movie()

            movie = Movie()
            popular = movie.popular()
            sleep(5)

            for p in popular:
                bot.send_message(call.message.chat.id,
                                 "Film name - " + p.title)
                sleep(1)
                bot.send_message(call.message.chat.id,
                                 "Overview - " + p.overview)
                sleep(1)

            bot.send_message(call.message.chat.id, "That's all for now😊")

    if call.message:
        if call.data == "live_currency":
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="Your Choice: Currency Rates",
                                  reply_markup=None)
            currency = types.InlineKeyboardMarkup()
            usd_rub = types.InlineKeyboardButton(text="USD -> RUB",
                                                 callback_data="usd_rub")
            rub_usd = types.InlineKeyboardButton(text="RUB -> USD",
                                                 callback_data="rub_usd")
            tr_usd = types.InlineKeyboardButton(text="TRY -> USD",
                                                callback_data="tr_usd")
            usd_tr = types.InlineKeyboardButton(text="USD -> TRY",
                                                callback_data="usd_tr")
            tr_rub = types.InlineKeyboardButton(text="TRY -> RUB",
                                                callback_data="tr_rub")
            rub_tr = types.InlineKeyboardButton(text="RUB -> TRY",
                                                callback_data="rub_tr")
            euro_rub = types.InlineKeyboardButton(text="EUR -> RUB",
                                                  callback_data="euro_rub")
            euro_usd = types.InlineKeyboardButton(text="EUR -> USD",
                                                  callback_data="euro_usd")
            euro_tr = types.InlineKeyboardButton(text="EUR -> TRY",
                                                 callback_data="euro_tr")
            usd_euro = types.InlineKeyboardButton(text="USD -> EUR",
                                                  callback_data="usd_euro")

            currency.add(usd_rub, rub_usd, tr_usd, usd_tr, rub_tr, tr_rub,
                         rub_tr, euro_tr, euro_usd, euro_rub, usd_euro)
            bot.send_message(call.message.chat.id,
                             "Choose one",
                             reply_markup=currency)

    if call.message:
        if call.data == "count_currency":
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="Your Choice: Count currency",
                                  reply_markup=None)
            currencyy = types.InlineKeyboardMarkup()
            usd_rubb = types.InlineKeyboardButton(text="USD -> RUB",
                                                  callback_data="usd_rubb")
            rub_usdd = types.InlineKeyboardButton(text="RUB -> USD",
                                                  callback_data="rub_usdd")
            tr_usdd = types.InlineKeyboardButton(text="TRY -> USD",
                                                 callback_data="tr_usdd")
            usd_trr = types.InlineKeyboardButton(text="USD -> TRY",
                                                 callback_data="usd_trr")
            tr_rubb = types.InlineKeyboardButton(text="TRY -> RUB",
                                                 callback_data="tr_rubb")
            rubb_try = types.InlineKeyboardButton(text="RUB -> TRY",
                                                  callback_data="rubb_try")
            euro_rub = types.InlineKeyboardButton(text="EUR -> RUB",
                                                  callback_data="euro_rubb")
            euro_usdd = types.InlineKeyboardButton(text="EUR -> USD",
                                                   callback_data="euro_usdd")
            euro_trr = types.InlineKeyboardButton(text="EUR -> TRY",
                                                  callback_data="euro_trr")
            usd_euuro = types.InlineKeyboardButton(text="USD -> EUR",
                                                   callback_data="usd_euuro")
            #talkk           =types.InlineKeyboardButton(text="Talk" , callback_data="talkk")

            currencyy.add(usd_rubb, rub_usdd, tr_usdd, usd_trr, tr_rubb,
                          rubb_try, euro_trr, euro_usdd, euro_rub, usd_euuro)
            bot.send_message(call.message.chat.id,
                             "Choose one",
                             reply_markup=currencyy)
    # I N L I N E ends here

    #  R A T E starts here
    if call.message:
        if call.data == "usd_euro":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nUSD -> EUR\n\nCost of 1$ is " +
                str(c.get_rate('USD', 'EUR')) + "€")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "USD -> EUR\n\nCost of 1$ is " +
                             str(c.get_rate('USD', 'EUR')) + "€",
                             reply_markup=markup)

    if call.message:
        if call.data == "usd_rub":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nUSD -> RUB\n\nCost of 1$ is " +
                str(c.get_rate('USD', 'RUB')) + "₽")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "USD -> RUB\n\nCost of 1$ is " +
                             str(c.get_rate('USD', 'RUB')) + "₽",
                             reply_markup=markup)

    if call.message:
        if call.data == "rub_usd":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nRUB -> USD\n\nCost of 1₽ is " +
                str(c.get_rate('RUB', 'USD')) + "$")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "RUB -> USD\n\nCost of 1₽ is " +
                             str(c.get_rate('RUB', 'USD')) + "$",
                             reply_markup=markup)

    if call.message:
        if call.data == "tr_usd":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nTRY -> USD\n\nCost of 1₺ is " +
                str(c.get_rate('TRY', 'USD')) + "$")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "TRY -> USD\n\nCost of 1₺ is " +
                             str(c.get_rate('TRY', 'USD')) + "$",
                             reply_markup=markup)

    if call.message:
        if call.data == "usd_tr":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nUSD -> TRY\n\nCost of 1$ is " +
                str(c.get_rate('USD', 'TRY')) + "₺")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "USD -> TRY\n\nCost of 1$ is " +
                             str(c.get_rate('USD', 'TRY')) + "₺",
                             reply_markup=markup)

    if call.message:
        if call.data == "rub_tr":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nRUB -> TRY\n\nCost of 1₽ is " +
                str(c.get_rate('RUB', 'TRY')) + "₺")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "RUB -> TRY\n\nCost of 1₽ is " +
                             str(c.get_rate('RUB', 'TRY')) + "₺",
                             reply_markup=markup)

    if call.message:
        if call.data == "tr_rub":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nTRY -> RUB\n\nCost of 1₺ is " +
                str(c.get_rate('TRY', 'RUB')) + "₽")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "TRY -> RUB\n\nCost of 1₺ is " +
                             str(c.get_rate('TRY', 'RUB')) + "₽",
                             reply_markup=markup)

    if call.message:
        if call.data == "euro_tr":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nEUR -> TRY\n\nCost of 1€ is " +
                str(c.get_rate('EUR', 'TRY')) + "₺")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "EUR -> TRY\n\nCost of 1€ is " +
                             str(c.get_rate('EUR', 'TRY')) + "₺",
                             reply_markup=markup)

    if call.message:
        if call.data == "euro_usd":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nEUR -> USD\n\nCost of 1€ is " +
                str(c.get_rate('EUR', 'USD')) + "$")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "EUR -> USD\n\nCost of 1€ is " +
                             str(c.get_rate('EUR', 'USD')) + "$",
                             reply_markup=markup)

    if call.message:
        if call.data == "euro_rub":
            markup = types.InlineKeyboardMarkup()
            switch_button = types.InlineKeyboardButton(
                text="Share",
                switch_inline_query="\n\nEUR -> RUB\n\nCost of 1€ is " +
                str(c.get_rate('EUR', 'RUB')) + "₽")
            markup.add(switch_button)
            bot.send_message(call.message.chat.id,
                             "EUR -> RUB\n\nCost of 1€ is " +
                             str(c.get_rate('EUR', 'RUB')) + "₽",
                             reply_markup=markup)

    # R A T E ends here
    if call.message:
        if call.data == "usd_euuro":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, dollar_euro)

    if call.message:
        if call.data == "rub_usdd":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, usd_rrub)

    if call.message:
        if call.data == "tr_usdd":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, tr_dollar)

    if call.message:
        if call.data == "usd_rubb":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, usd_rubl)

    if call.message:
        if call.data == "usd_trr":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, usd_turkey)

    if call.message:
        if call.data == "tr_rubb":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, tr_ruble)

    if call.message:
        if call.data == "rubb_try":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, ruble_tr)

    if call.message:
        if call.data == "euro_rubb":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, eur_rubb)

    if call.message:
        if call.data == "euro_usdd":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, euro_dollar)

    if call.message:
        if call.data == "euro_trr":
            bot.send_message(call.message.chat.id, "Type ONLY amount")
            bot.register_next_step_handler(call.message, euro_turk)

    if call.message:
        if call.data == 'english':
            bot.send_message(
                call.message.chat.id,
                "Just enter text. To translate to english language you don't need to specify your language. Just enter text in your language."
            )
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="🇬🇧 English 🇬🇧",
                                  reply_markup=None)
            bot.register_next_step_handler(call.message, in_english)

    if call.message:
        if call.data == 'russian':
            bot.send_message(call.message.chat.id, "Just enter text")
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="🇷🇺 Russian 🇷🇺",
                                  reply_markup=None)
            bot.register_next_step_handler(call.message, in_russian)

    if call.message:
        if call.data == 'turkish':
            bot.send_message(call.message.chat.id, "Just enter text")
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="🇹🇷 Turkish 🇹🇷",
                                  reply_markup=None)
            bot.register_next_step_handler(call.message, in_turkish)
    if call.message:
        if call.data == 'czech':
            bot.send_message(call.message.chat.id, "Just enter text")
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="🇨🇿 Czech 🇨🇿",
                                  reply_markup=None)
            bot.register_next_step_handler(call.message, in_czech)
    if call.message:
        if call.data == "spanish":
            bot.send_message(call.message.chat.id, "Just enter text")
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="🇪🇸 Spanish 🇪🇸",
                                  reply_markup=None)
            bot.register_next_step_handler(call.message, in_spanish)
    if call.message:
        if call.data == "azeri":
            bot.send_message(call.message.chat.id, "Just enter text")
            bot.edit_message_text(chat_id=call.message.chat.id,
                                  message_id=call.message.message_id,
                                  text="🇦🇿 Azerbaijani 🇦🇿",
                                  reply_markup=None)
            bot.register_next_step_handler(call.message, in_azeri)

    if call.message:
        if call.data == "talkk":
            bot.send_message(call.message.chat.id, "Hi:)")
            bot.register_next_step_handler(call.message, talk_to_me)
Esempio n. 11
0
class MovieTests(unittest.TestCase):
    def setUp(self):
        self.tmdb = TMDb()
        self.tmdb.api_key = os.environ['TMDB_API_KEY']
        self.tmdb.language = "en"
        self.tmdb.debug = True
        self.tmdb.wait_on_rate_limit = True
        self.tmdb.cache = False
        self.movie = Movie()

    def test_get_movie_repr(self):
        search = self.movie.search("Mad Max")
        self.assertGreater(len(search), 0)
        for result in search:
            self.assertNotEqual(str(result), "TMDB Obj")

    def test_get_movie_details(self):
        movie = self.movie.details(111)
        self.assertIsNotNone(movie)
        self.assertEqual(movie.id, 111)
        self.assertTrue(hasattr(movie, 'title'))
        self.assertTrue(hasattr(movie, 'overview'))
        self.assertTrue(hasattr(movie, 'release_dates'))

    def test_get_movie_alternative_titles(self):
        alternative_titles = self.movie.alternative_titles(111)
        self.assertEqual(alternative_titles.id, 111)
        self.assertGreater(len(alternative_titles.titles), 0)
        for title in alternative_titles.titles:
            self.assertIn('iso_3166_1', title)
            self.assertIn('title', title)
            self.assertIn('type', title)

    def test_get_movie_changes(self):
        changes = self.movie.changes(111,
                                     start_date="2016-08-29",
                                     end_date="2016-09-10")
        self.assertIsNotNone(changes)
        changes = self.movie.changes(111, start_date="2016-08-29")
        self.assertIsNotNone(changes)
        changes = self.movie.changes(111, end_date="2016-09-10")
        self.assertIsNotNone(changes)
        changes = self.movie.changes(111, page=2)
        self.assertIsNotNone(changes)

    def test_get_movie_credits(self):
        credits = self.movie.credits(111)
        self.assertEqual(credits.id, 111)
        self.assertTrue(hasattr(credits, "cast"))
        self.assertTrue(hasattr(credits, "crew"))

    def test_get_movie_external_ids(self):
        external_ids = self.movie.external_ids(111)
        self.assertIn("imdb_id", external_ids)
        self.assertIn("facebook_id", external_ids)
        self.assertIn("instagram_id", external_ids)
        self.assertIn("twitter_id", external_ids)
        self.assertIn("id", external_ids)

    def test_get_movie_images(self):
        images = self.movie.images(111, include_image_language="en,null")
        self.assertEqual(images.id, 111)
        self.assertGreater(len(images.backdrops), 0)
        self.assertGreater(len(images.posters), 0)
        for image in images.backdrops:
            self.assertIn("file_path", image)
        for image in images.posters:
            self.assertIn("file_path", image)

    def test_get_movie_keywords(self):
        keywords = self.movie.keywords(111)
        for keyword in keywords.keywords:
            self.assertIn("id", keyword)
            self.assertIn("name", keyword)

    def test_get_movie_lists(self):
        lists = self.movie.lists(111)
        self.assertGreater(len(lists), 0)
        for list in lists:
            self.assertTrue(hasattr(list, "description"))
            self.assertTrue(hasattr(list, "name"))

    def test_get_movie_recommendations(self):
        recommendations = self.movie.recommendations(111)
        self.assertGreater(len(recommendations), 0)
        for movie in recommendations:
            self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_release_dates(self):
        release_dates = self.movie.release_dates(111)
        self.assertIsNotNone(release_dates)
        self.assertEqual(release_dates.id, 111)

    def test_get_movie_reviews(self):
        reviews = self.movie.reviews(111)
        self.assertGreater(len(reviews), 0)
        for review in reviews:
            self.assertTrue(hasattr(review, "id"))
            self.assertTrue(hasattr(review, "content"))

    def test_get_movie_videos(self):
        videos = self.movie.videos(111)
        self.assertGreater(len(videos), 0)
        for video in videos:
            self.assertTrue(hasattr(video, "id"))

    def test_get_movie_latest(self):
        latest = self.movie.latest()
        self.assertIsNotNone(latest)
        self.assertTrue(hasattr(latest, "id"))

    def test_get_movie_now_playing(self):
        now_playing = self.movie.now_playing()
        self.assertGreater(len(now_playing), 0)
        for movie in now_playing:
            self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_top_rated(self):
        top_rated = self.movie.top_rated()
        self.assertGreater(len(top_rated), 0)
        for movie in top_rated:
            self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_upcoming(self):
        upcoming = self.movie.upcoming()
        self.assertGreater(len(upcoming), 0)
        for movie in upcoming:
            self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_popular(self):
        popular = self.movie.popular()
        self.assertGreater(len(popular), 0)
        for movie in popular:
            self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_search(self):
        search = self.movie.search("Mad Max")
        self.assertGreater(len(search), 0)
        for movie in search:
            self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_similar(self):
        similar = self.movie.similar(111)
        self.assertGreater(len(similar), 0)
        for movie in similar:
            self.assertTrue(hasattr(movie, "id"))

    def test_get_movie_external(self):
        external = self.movie.external(external_id="tt8155288",
                                       external_source="imdb_id")
        self.assertGreater(len(external), 0)
        for movie in external["movie_results"]:
            self.assertIn("id", movie)
            external_ids = self.movie.external_ids(movie["id"])
            self.assertEqual(external_ids["imdb_id"], "tt8155288")
Esempio n. 12
0
# Filmes mais popularies
popular = movie.popular()
tabela01 = []
for p in popular:
    tbl = [
        p.id, p.title, p.overview, p.popularity, p.vote_count, p.release_date
    ]
    tabela01.append(tbl)
MoviePopular = pd.DataFrame(tabela01,
                            columns=[
                                'ID', 'Titulo', 'Resumo', 'Popularidade',
                                'QtdVotos', 'DataLancamento'
                            ])

# Filmes recomendados
recomendacao = movie.recommendations(movie_id=111)
tabela02 = []
for a in recomendacao:
    tbl = [
        a.id, a.original_language, a.original_title, a.overview, a.title,
        a.release_date, a.popularity, a.vote_average, a.vote_count
    ]
    tabela02.append(tbl)
MovieRecomendacao = pd.DataFrame(tabela02,
                                 columns=[
                                     'ID', 'IdiomaOriginal', 'TituloOriginal',
                                     'Resumo', 'Titulo', 'DataLancamento',
                                     'Popularidade', 'MediaVotos', 'QtdVotos'
                                 ])

# review de Movies
Esempio n. 13
0
# Simple program that takes a movie name as an argument and finds movie recommendations for the user.

from tmdbv3api import TMDb, Movie
from argparse import ArgumentParser

tmdb = TMDb()
tmdb.api_key = ''

if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument('movie')
    parser.add_argument('--limit', nargs='?', default=1)
    args = parser.parse_args()
    movie = Movie()
    search = movie.search(args.movie)
    first_result = search[0]
    recommendations = movie.recommendations(first_result.id)
    recommendations = recommendations[:int(
        args.limit)] if recommendations >= args.limit else recommendations
    for recommendation in recommendations:
        print("%s (%s)" % (recommendation.title, recommendation.release_date))