Skip to content

Commit

Permalink
👽 Movie: OMDb -> TMDb (#251)
Browse files Browse the repository at this point in the history
Fix #242 

* Reworked module to rely on TMDB.

* Update config.py

* Update movie.py

* Update movie.py

* Made API calls rely on parameters dict

* Update movie.py

* Update movie.py

* Update movie.py
  • Loading branch information
Daniel Edades authored and swapagarwal committed Aug 6, 2017
1 parent 7256d76 commit 52e0f25
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Feel free to add to this list by opening an Issue / Pull Request.
| help | What can you do? | --- |
| joke | tell me a joke | [Offline](https://github.com/swapagarwal/JARVIS-on-Messenger/blob/master/data/jokes.json) |
| lyrics | paradise lyrics | Powered by musiXmatch |
| movie | iron man 2 movie plot | OMDb API |
| movie | iron man 2 movie plot | <img src="/images/powered_by_tmdb.png"/> |
| music | songs by linkin park | Spotify |
| news | latest news | Powered by NewsAPI |
| ping | ping google.com | Is it up? |
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
OPEN_WEATHER_MAP_ACCESS_TOKEN = '<<OPEN_WEATHER_MAP_ACCESS_TOKEN>>'
SPOTIFY_API_KEY = '<<SPOTIFY_API_KEY>>'
TIME_ZONE_DB_API_KEY = '<<TIME_ZONE_DB_API_KEY>>'
TMDB_API_KEY = '<<TMDB_API_KEY>>'
WORDS_API_KEY = '<<WORDS_API_KEY>>'
YOUTUBE_DATA_API_KEY = '<<YOUTUBE_DATA_API_KEY>>'
Binary file added images/powered_by_tmdb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 30 additions & 5 deletions modules/src/movie.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
import os

import requests
import requests_cache

import config
from templates.button import *

# This product uses the TMDb API but is not endorsed or certified by TMDb.
TMDB_API_KEY = os.environ.get('TMDB_API_KEY', config.TMDB_API_KEY)


def process(input, entities):
output = {}
try:
movie = entities['movie'][0]['value']

with requests_cache.enabled('movie_cache', backend='sqlite', expire_after=86400):
r = requests.get('http://www.omdbapi.com/?t=' + movie + '&plot=full&r=json')
# Make a search request to the API to get the movie's TMDb ID
r = requests.get('http://api.themoviedb.org/3/search/movie', params={
'api_key': TMDB_API_KEY,
'query': movie,
'include_adult': False
})
data = r.json()
output['input'] = input
template = TextTemplate('Title: ' + data['Title'] + '\nYear: ' + data['Year'] + '\nIMDb Rating: ' + data[
'imdbRating'] + ' / 10' + '\nPlot: ' + data['Plot'])

assert (len(data['results']) > 0)
tmdb_id = str(data['results'][0]['id'])

# Make another request to the API using the movie's TMDb ID to get the movie's IMDb ID
r = requests.get('https://api.themoviedb.org/3/movie/' + tmdb_id, params={
'api_key': TMDB_API_KEY
})
data = r.json()

template = TextTemplate('Title: ' + data['title'] +
'\nYear: ' + data['release_date'][:4] +
'\nAverage Rating: ' + str(data['vote_average']) + ' / 10' +
'\nOverview: ' + data['overview'])
text = template.get_text()
template = ButtonTemplate(text)
template.add_web_url('IMDb Link', 'http://www.imdb.com/title/' + data['imdbID'] + '/')
template.add_web_url('IMDb Link', 'https://www.imdb.com/title/' + data['imdb_id'] + '/')

output['input'] = input
output['output'] = template.get_message()
output['success'] = True
except:
Expand Down

0 comments on commit 52e0f25

Please sign in to comment.