From 44a6603321d6fe498066db6b791b79d127b2861a Mon Sep 17 00:00:00 2001 From: theo Date: Sat, 15 Jun 2019 15:08:36 +0200 Subject: [PATCH 01/11] Recommend module is start --- bridges/python/Pipfile | 1 + bridges/python/Pipfile.lock | 14 ++++-- package-lock.json | 28 ++++++++--- packages/cinema/README.md | 0 packages/cinema/__init__.py | 0 packages/cinema/cinema.py | 58 +++++++++++++++++++++++ packages/cinema/config/config.sample.json | 6 +++ packages/cinema/data/answers/en.json | 11 +++++ packages/cinema/data/expressions/en.json | 10 ++++ packages/cinema/version.txt | 1 + 10 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 packages/cinema/README.md create mode 100644 packages/cinema/__init__.py create mode 100644 packages/cinema/cinema.py create mode 100644 packages/cinema/config/config.sample.json create mode 100644 packages/cinema/data/answers/en.json create mode 100644 packages/cinema/data/expressions/en.json create mode 100644 packages/cinema/version.txt diff --git a/bridges/python/Pipfile b/bridges/python/Pipfile index 5af4c007c..4e7695306 100644 --- a/bridges/python/Pipfile +++ b/bridges/python/Pipfile @@ -8,5 +8,6 @@ requests = "==2.21.0" pytube = "==9.5.0" tinydb = "==3.9.0" beautifulsoup4 = "==4.7.1" +tmdbsimple = "==2.2.0" [dev-packages] diff --git a/bridges/python/Pipfile.lock b/bridges/python/Pipfile.lock index 54fc9aed1..9da87c6fa 100644 --- a/bridges/python/Pipfile.lock +++ b/bridges/python/Pipfile.lock @@ -1,12 +1,10 @@ { "_meta": { "hash": { - "sha256": "73bde89b379ffec7cec145fa30f1ebb49c349204b730a94108151fd9b71b31ec" + "sha256": "18fcaba60d56141e0e72fe9b030659fbcef1065ed0a3d73e8832b1dabf994a4c" }, "pipfile-spec": 6, - "requires": { - "python_version": "3.6" - }, + "requires": {}, "sources": [ { "name": "pypi", @@ -77,6 +75,14 @@ "index": "pypi", "version": "==3.9.0" }, + "tmdbsimple": { + "hashes": [ + "sha256:3383780ae40fbc2b5197feb06496f81f3a5c0ff3336a2a971a51e638fb10c895", + "sha256:cd8c5bc3599e803f1f908339b3d010e138722d147f10ed410b3205c72db0c00c" + ], + "index": "pypi", + "version": "==2.2.0" + }, "urllib3": { "hashes": [ "sha256:2393a695cd12afedd0dcb26fe5d50d0cf248e5a66f75dbd89a3d4eb333a61af4", diff --git a/package-lock.json b/package-lock.json index 3a963b8d5..d91439d61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5464,12 +5464,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5484,17 +5486,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -5611,7 +5616,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -5623,6 +5629,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5637,6 +5644,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5644,12 +5652,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5668,6 +5678,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -5748,7 +5759,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -5760,6 +5772,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -5881,6 +5894,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/packages/cinema/README.md b/packages/cinema/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/cinema/__init__.py b/packages/cinema/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/packages/cinema/cinema.py b/packages/cinema/cinema.py new file mode 100644 index 000000000..854ee198f --- /dev/null +++ b/packages/cinema/cinema.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- + +import utils +import tmdbsimple as tmdb +import functools +import random as ran + +# Package database +db = utils.db()['db'] + +# Query +Query = utils.db()['query']() + + +def load_config(func): + @functools.wraps(func) + def wrapper_load_config(string, entities): + payload = dict() + payload["string"] = string + payload["entities"] = entities + # ISO 639-1 language code + payload["lang"] = utils.getqueryobj()["lang"][:2] + + payload["API_KEY"] = utils.config('API_KEY') + tmdb.API_KEY = payload["API_KEY"] + + return func(payload) + + return wrapper_load_config + + +@load_config +def recommend(payload): + if db.search(Query.type == 'rmovie_request'): + payload["movie"] = db.search(Query.type == 'rmovie_request')[0]['content'] + o_id = db.search(Query.type == 'rmovie_request')[0]['old_id'] + o_id = o_id + 1 + db.update({"old_id": o_id}, Query.type == 'rmovie_request') + db.remove(Query.type == 'rmovie_request' and Query.old_id > 10) + else: + # Get an random movie with user's language + payload["movie"] = tmdb.Discover().movie( + page=ran.randint(0, 1000), + language=payload["lang"], + vote_average_gte=5.00) + db.insert({'type': 'rmovie_request','old_id': 0, 'content': payload["movie"]}) + + movie_nO = ran.randint(0, 20) + movie = payload["movie"]["results"][movie_nO] + movie_title = movie["title"] + movie_rdate = movie["release_date"] + movie_sum = movie["overview"] + + return utils.output('end', 'recommend', utils.translate('recommend', { + "movie_title": movie_title, + "release_date": movie_rdate, + "summarize": movie_sum})) diff --git a/packages/cinema/config/config.sample.json b/packages/cinema/config/config.sample.json new file mode 100644 index 000000000..41c1fd14f --- /dev/null +++ b/packages/cinema/config/config.sample.json @@ -0,0 +1,6 @@ +{ + "cinema": { + "API_KEY": "EMPTY", + "options": {} + } +} diff --git a/packages/cinema/data/answers/en.json b/packages/cinema/data/answers/en.json new file mode 100644 index 000000000..ecb3a7213 --- /dev/null +++ b/packages/cinema/data/answers/en.json @@ -0,0 +1,11 @@ +{ + "cinema": { + "recommend": [ + "I advise you to watch %movie_title% released on %release_date%, it can be summarized as follows :

\n %summarize%

", + "I recommend you to watch %movie_title% released on %release_date%, it can be summarized as follows :

\n %summarize%

" + ], + "test":[ + "%test%" + ] + } +} diff --git a/packages/cinema/data/expressions/en.json b/packages/cinema/data/expressions/en.json new file mode 100644 index 000000000..01e8e40ed --- /dev/null +++ b/packages/cinema/data/expressions/en.json @@ -0,0 +1,10 @@ +{ + "cinema": { + "recommend":{ + "expressions":[ + "Leon, can you recommend a movie ?", + "Can you recommend a film ?" + ] + } + } +} diff --git a/packages/cinema/version.txt b/packages/cinema/version.txt new file mode 100644 index 000000000..77d6f4ca2 --- /dev/null +++ b/packages/cinema/version.txt @@ -0,0 +1 @@ +0.0.0 From 03de1cceeb137f3707ce553e428336252d520e3a Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Sun, 16 Jun 2019 12:42:39 +0200 Subject: [PATCH 02/11] change 'EMPTY' by 'YOUR_API_KEY' --- packages/cinema/config/config.sample.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cinema/config/config.sample.json b/packages/cinema/config/config.sample.json index 41c1fd14f..00e58759e 100644 --- a/packages/cinema/config/config.sample.json +++ b/packages/cinema/config/config.sample.json @@ -1,6 +1,6 @@ { "cinema": { - "API_KEY": "EMPTY", + "API_KEY": "YOUR_API_KEY", "options": {} } } From 13e40603a9b02725e055f4157ac324bab4c57c27 Mon Sep 17 00:00:00 2001 From: theo Date: Sun, 16 Jun 2019 17:45:31 +0200 Subject: [PATCH 03/11] now_theatre function works --- packages/cinema/cinema.py | 17 +++++++++++++++++ packages/cinema/data/answers/en.json | 5 ++++- packages/cinema/data/expressions/en.json | 7 ++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/cinema/cinema.py b/packages/cinema/cinema.py index 854ee198f..12d7414dd 100644 --- a/packages/cinema/cinema.py +++ b/packages/cinema/cinema.py @@ -5,6 +5,7 @@ import tmdbsimple as tmdb import functools import random as ran +import datetime as dt # Package database db = utils.db()['db'] @@ -21,6 +22,7 @@ def wrapper_load_config(string, entities): payload["entities"] = entities # ISO 639-1 language code payload["lang"] = utils.getqueryobj()["lang"][:2] + payload["today"] = dt.date.today() payload["API_KEY"] = utils.config('API_KEY') tmdb.API_KEY = payload["API_KEY"] @@ -56,3 +58,18 @@ def recommend(payload): "movie_title": movie_title, "release_date": movie_rdate, "summarize": movie_sum})) + + +@load_config +def now_theatres(payload): + now_in_theatres = tmdb.Discover().movie( + primary_release_date=payload["today"], + language=payload["lang"]) + res = 'The films currently in the cinema are:
    ' + for title in now_in_theatres["results"]: + res = res+"
  • "+title["title"]+"
  • "+"
    " + res = res + "
" + + return utils.output("end", "nit_title_list", utils.translate('nit_list', { + "nit_title": res + })) diff --git a/packages/cinema/data/answers/en.json b/packages/cinema/data/answers/en.json index ecb3a7213..c656cc645 100644 --- a/packages/cinema/data/answers/en.json +++ b/packages/cinema/data/answers/en.json @@ -6,6 +6,9 @@ ], "test":[ "%test%" - ] + ], + "nit_list":[ + "%nit_title%" + ] } } diff --git a/packages/cinema/data/expressions/en.json b/packages/cinema/data/expressions/en.json index 01e8e40ed..bff929748 100644 --- a/packages/cinema/data/expressions/en.json +++ b/packages/cinema/data/expressions/en.json @@ -5,6 +5,11 @@ "Leon, can you recommend a movie ?", "Can you recommend a film ?" ] - } + }, + "now_theatres":{ + "expressions":[ + "What movies are in theatres?" + ] + } } } From d343406926300fd78cc09c5556e13573ea1f3d83 Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Wed, 3 Jul 2019 23:26:26 +0200 Subject: [PATCH 04/11] info tv + movie | discover serie --- package-lock.json | 13 ++- packages/Pipfile | 0 packages/cinema/cinema.py | 116 ++++++++++++++++++----- packages/cinema/data/answers/en.json | 6 ++ packages/cinema/data/expressions/en.json | 55 ++++++++++- packages/cinema/data/words/movie.json | 1 + packages/cinema/data/words/serie.json | 1 + 7 files changed, 160 insertions(+), 32 deletions(-) create mode 100644 packages/Pipfile create mode 100644 packages/cinema/data/words/movie.json create mode 100644 packages/cinema/data/words/serie.json diff --git a/package-lock.json b/package-lock.json index d91439d61..9bad0c0c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5443,7 +5443,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -5858,7 +5859,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -5914,6 +5916,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -5957,12 +5960,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/packages/Pipfile b/packages/Pipfile new file mode 100644 index 000000000..e69de29bb diff --git a/packages/cinema/cinema.py b/packages/cinema/cinema.py index 12d7414dd..a0f69c9a0 100644 --- a/packages/cinema/cinema.py +++ b/packages/cinema/cinema.py @@ -6,6 +6,7 @@ import functools import random as ran import datetime as dt +import json # Package database db = utils.db()['db'] @@ -27,6 +28,12 @@ def wrapper_load_config(string, entities): payload["API_KEY"] = utils.config('API_KEY') tmdb.API_KEY = payload["API_KEY"] + with open('packages/cinema/data/words/movie.json') as json_data: + payload["trl_movie"] = json.load(json_data) + with open('packages/cinema/data/words/serie.json') as json_data: + payload["trl_serie"] = json.load(json_data) + + return func(payload) return wrapper_load_config @@ -34,30 +41,75 @@ def wrapper_load_config(string, entities): @load_config def recommend(payload): - if db.search(Query.type == 'rmovie_request'): - payload["movie"] = db.search(Query.type == 'rmovie_request')[0]['content'] - o_id = db.search(Query.type == 'rmovie_request')[0]['old_id'] - o_id = o_id + 1 - db.update({"old_id": o_id}, Query.type == 'rmovie_request') - db.remove(Query.type == 'rmovie_request' and Query.old_id > 10) - else: - # Get an random movie with user's language - payload["movie"] = tmdb.Discover().movie( - page=ran.randint(0, 1000), - language=payload["lang"], - vote_average_gte=5.00) - db.insert({'type': 'rmovie_request','old_id': 0, 'content': payload["movie"]}) - - movie_nO = ran.randint(0, 20) - movie = payload["movie"]["results"][movie_nO] - movie_title = movie["title"] - movie_rdate = movie["release_date"] - movie_sum = movie["overview"] - - return utils.output('end', 'recommend', utils.translate('recommend', { - "movie_title": movie_title, - "release_date": movie_rdate, - "summarize": movie_sum})) + flag_movie = 0 + flag_serie = 0 + for item in payload["entities"]: + if item["entity"] == "Serie_Or_Movie": + word = item["sourceText"] + i = 0 + wflag = 0 + while i < 92 and wflag == 0: + if payload["trl_movie"][i]["string"] == word: + flag_movie = 1 + wflag = 1 + elif payload["trl_serie"][i]["string"] == word: + flag_serie = 1 + wflag = 1 + i = i + 1 + else: + return utils.output('end', 'Error', utils.translate('Error')) + + if flag_movie == 1: + if db.search(Query.type == 'rmovie_request'): + payload["movie"] = db.search(Query.type == 'rmovie_request')[0]['content'] + o_id = db.search(Query.type == 'rmovie_request')[0]['old_id'] + o_id = o_id + 1 + db.update({"old_id": o_id}, Query.type == 'rmovie_request') + db.remove(Query.type == 'rmovie_request' and Query.old_id > 10) + else: + # Get an random movie with user's language + payload["movie"] = tmdb.Discover().movie( + page=ran.randint(0, 1000), + language=payload["lang"], + vote_average_gte=7.00) + db.insert({'type': 'rmovie_request','old_id': 0, 'content': payload["movie"]}) + + movie_nO = ran.randint(0, 20) + movie = payload["movie"]["results"][movie_nO] + movie_title = movie["title"] + movie_rdate = movie["release_date"] + movie_sum = movie["overview"] + + return utils.output('end', 'recommend', utils.translate('recommend', { + "movie_title": movie_title, + "release_date": movie_rdate, + "summarize": movie_sum})) + + elif flag_serie == 1: + if db.search(Query.type == 'rserie_request'): + payload["serie"] = db.search(Query.type == 'rserie_request')[0]['content'] + o_id = db.search(Query.type == 'rserie_request')[0]['old_id'] + o_id = o_id + 1 + db.update({"old_id": o_id}, Query.type == 'rserie_request') + db.remove(Query.type == 'rserie_request' and Query.old_id > 10) + else: + # Get an random serie with user's language + payload["serie"] = tmdb.Discover().tv( + page=ran.randint(0, 1000), + language=payload["lang"], + vote_average_gte=7.00) + db.insert({'type': 'rserie_request','old_id': 0, 'content': payload["movie"]}) + + serie_nO = ran.randint(0, 20) + serie = payload["serie"]["results"][serie_nO] + serie_title = serie["name"] + serie_rdate = serie["first_air_date"] + serie_sum = serie["overview"] + + return utils.output('end', 'recommend', utils.translate('recommend', { + "movie_title": serie_title, + "release_date": serie_rdate, + "summarize": serie_sum})) @load_config @@ -73,3 +125,19 @@ def now_theatres(payload): return utils.output("end", "nit_title_list", utils.translate('nit_list', { "nit_title": res })) + +@load_config +def info(payload): + for item in payload["entities"]: + if item["entity"] == "title": + data_title = item["sourceText"] + + data_info = tmdb.Search().collection(query=data_title, language=payload["lang"]) + if data_info["total_results"] == 0: + data_info = tmdb.Search().multi(query=data_title, language=payload["lang"]) + + data_overview = data_info["results"][0]["overview"] + + return utils.output("end", "info", utils.translate('info', { + "title": data_title.title(), + "overview": data_overview})) diff --git a/packages/cinema/data/answers/en.json b/packages/cinema/data/answers/en.json index c656cc645..6349e07e2 100644 --- a/packages/cinema/data/answers/en.json +++ b/packages/cinema/data/answers/en.json @@ -9,6 +9,12 @@ ], "nit_list":[ "%nit_title%" + ], + "info":[ + "%title% can be summarized as follows : %overview% " + ], + "error":[ + "Error" ] } } diff --git a/packages/cinema/data/expressions/en.json b/packages/cinema/data/expressions/en.json index bff929748..607a53a0f 100644 --- a/packages/cinema/data/expressions/en.json +++ b/packages/cinema/data/expressions/en.json @@ -2,13 +2,60 @@ "cinema": { "recommend":{ "expressions":[ - "Leon, can you recommend a movie ?", - "Can you recommend a film ?" - ] + "Leon, can you recommend a ?", + "Can you recommend a ?" + ], + "entities": [ + { + "type": "trim", + "name": "Serie_Or_Movie", + "conditions": [ + { + "type": "between", + "from": "a", + "to": "?" + } + ] + } + ] }, "now_theatres":{ "expressions":[ - "What movies are in theatres?" + "What movies are in theatres?" + ] + }, + "info":{ + "expressions":[ + "Can you provide information about with moviedb?", + "Give information about with moviedb" + ], + "entities": [ + { + "type": "trim", + "name": "title", + "conditions": [ + { + "type": "between", + "from": "about", + "to": "with" + }, + { + "type": "after_last", + "from": "about" + } + ] + }, + { + "type": "trim", + "name": "API", + "conditions": [ + { + "type": "between", + "from": "with", + "to": "?" + } + ] + } ] } } diff --git a/packages/cinema/data/words/movie.json b/packages/cinema/data/words/movie.json new file mode 100644 index 000000000..e6772ca5b --- /dev/null +++ b/packages/cinema/data/words/movie.json @@ -0,0 +1 @@ +[{"locale":"af","country":"Afrikaans","string":"Fliek"},{"locale":"ar","country":"Arabic","string":"فيلم"},{"locale":"az","country":"Azerbaijani","string":"film"},{"locale":"be","country":"Belarusian","string":"фільм"},{"locale":"bg","country":"Bulgarian","string":"филм"},{"locale":"bn","country":"Bengali","string":"সিনেমা"},{"locale":"bs","country":"Bosnian","string":"film"},{"locale":"ca","country":"Catalan","string":"pel·lícula"},{"locale":"ceb","country":"Cebuano","string":"movie"},{"locale":"cs","country":"Czech","string":"film"},{"locale":"cy","country":"Welsh","string":"ffilm"},{"locale":"da","country":"Danish","string":"film"},{"locale":"de","country":"German","string":"Film"},{"locale":"el","country":"Greek","string":"ταινία"},{"locale":"en","country":"English","string":"movie"},{"locale":"eo","country":"Esperanto","string":"movie"},{"locale":"es","country":"Spanish","string":"película"},{"locale":"et","country":"Estonian","string":"Film"},{"locale":"eu","country":"Basque","string":"movie"},{"locale":"fa","country":"Persian","string":"فیلم سینما"},{"locale":"fi","country":"Finnish","string":"elokuva"},{"locale":"fr","country":"French","string":"film"},{"locale":"ga","country":"Irish","string":"scannán"},{"locale":"gl","country":"Galician","string":"película"},{"locale":"gu","country":"Gujarati","string":"મૂવી"},{"locale":"ha","country":"Hausa","string":"fim"},{"locale":"hi","country":"Hindi","string":"चलचित्र"},{"locale":"hmn","country":"Hmong","string":"movie"},{"locale":"hr","country":"Croatian","string":"film"},{"locale":"ht","country":"Haitian Creole","string":"fim"},{"locale":"hu","country":"Hungarian","string":"film"},{"locale":"hy","country":"Armenian","string":"ֆիլմը"},{"locale":"id","country":"Indonesian","string":"film"},{"locale":"ig","country":"Igbo","string":"ihe nkiri"},{"locale":"is","country":"Icelandic","string":"bíómynd"},{"locale":"it","country":"Italian","string":"film"},{"locale":"iw","country":"Hebrew","string":"סרט"},{"locale":"ja","country":"Japanese","string":"映画"},{"locale":"jw","country":"Javanese","string":"film"},{"locale":"ka","country":"Georgian","string":"ფილმი"},{"locale":"kk","country":"Kazakh","string":"фильм"},{"locale":"km","country":"Khmer","string":"ខ្សែភាពយន្ត"},{"locale":"kn","country":"Kannada","string":"ಚಲನಚಿತ್ರ"},{"locale":"ko","country":"Korean","string":"영화"},{"locale":"la","country":"Latin","string":"movie"},{"locale":"lo","country":"Lao","string":"ຮູບ​ເງົາ"},{"locale":"lt","country":"Lithuanian","string":"filmas"},{"locale":"lv","country":"Latvian","string":"filmu"},{"locale":"mg","country":"Malagasy","string":"sarimihetsika"},{"locale":"mi","country":"Maori","string":"kiriata"},{"locale":"mk","country":"Macedonian","string":"филм"},{"locale":"ml","country":"Malayalam","string":"സിനിമ"},{"locale":"mn","country":"Mongolian","string":"кино"},{"locale":"mr","country":"Marathi","string":"चित्रपट"},{"locale":"ms","country":"Malay","string":"filem"},{"locale":"mt","country":"Maltese","string":"film"},{"locale":"my","country":"Myanmar (Burmese)","string":"ရုပ်ရှင်"},{"locale":"ne","country":"Nepali","string":"चलचित्र"},{"locale":"nl","country":"Dutch","string":"film"},{"locale":"no","country":"Norwegian","string":"film"},{"locale":"ny","country":"Chichewa","string":"kanema"},{"locale":"pa","country":"Punjabi","string":"ਫਿਲਮ"},{"locale":"pl","country":"Polish","string":"film"},{"locale":"pt","country":"Portuguese","string":"filme"},{"locale":"ro","country":"Romanian","string":"film"},{"locale":"ru","country":"Russian","string":"кино"},{"locale":"si","country":"Sinhala","string":"චිත්රපටය"},{"locale":"sk","country":"Slovak","string":"film"},{"locale":"sl","country":"Slovenian","string":"film"},{"locale":"so","country":"Somali","string":"filim"},{"locale":"sq","country":"Albanian","string":"film"},{"locale":"sr","country":"Serbian","string":"филм"},{"locale":"st","country":"Sesotho","string":"filimi"},{"locale":"su","country":"Sundanese","string":"Pilem"},{"locale":"sv","country":"Swedish","string":"film"},{"locale":"sw","country":"Swahili","string":"movie"},{"locale":"ta","country":"Tamil","string":"திரைப்பட"},{"locale":"te","country":"Telugu","string":"సినిమా"},{"locale":"tg","country":"Tajik","string":"филм"},{"locale":"th","country":"Thai","string":"หนัง"},{"locale":"tl","country":"Filipino","string":"pelikula"},{"locale":"tr","country":"Turkish","string":"film"},{"locale":"uk","country":"Ukrainian","string":"фільм"},{"locale":"ur","country":"Urdu","string":"فلم"},{"locale":"uz","country":"Uzbek","string":"film"},{"locale":"vi","country":"Vietnamese","string":"bộ phim"},{"locale":"yi","country":"Yiddish","string":"פֿילם"},{"locale":"yo","country":"Yoruba","string":"fiimu"},{"locale":"zh","country":"Chinese","string":"电影"},{"locale":"zh-CN","country":"Chinese (Simplified)","string":"电影"},{"locale":"zh-TW","country":"Chinese (Traditional)","string":"電影"},{"locale":"zu","country":"Zulu","string":"movie"}] diff --git a/packages/cinema/data/words/serie.json b/packages/cinema/data/words/serie.json new file mode 100644 index 000000000..0fc363cdb --- /dev/null +++ b/packages/cinema/data/words/serie.json @@ -0,0 +1 @@ +[{"locale":"af","country":"Afrikaans","string":"reeks"},{"locale":"ar","country":"Arabic","string":"سلسلة"},{"locale":"az","country":"Azerbaijani","string":"seriya"},{"locale":"be","country":"Belarusian","string":"серыя"},{"locale":"bg","country":"Bulgarian","string":"серия"},{"locale":"bn","country":"Bengali","string":"ক্রম"},{"locale":"bs","country":"Bosnian","string":"serija"},{"locale":"ca","country":"Catalan","string":"sèrie"},{"locale":"ceb","country":"Cebuano","string":"sunod-sunod nga"},{"locale":"cs","country":"Czech","string":"série"},{"locale":"cy","country":"Welsh","string":"cyfres"},{"locale":"da","country":"Danish","string":"serie"},{"locale":"de","country":"German","string":"serie"},{"locale":"el","country":"Greek","string":"σειρά"},{"locale":"en","country":"English","string":"serie"},{"locale":"eo","country":"Esperanto","string":"serie"},{"locale":"es","country":"Spanish","string":"serie"},{"locale":"et","country":"Estonian","string":"seeria"},{"locale":"eu","country":"Basque","string":"series"},{"locale":"fa","country":"Persian","string":"سلسله"},{"locale":"fi","country":"Finnish","string":"sarja"},{"locale":"fr","country":"French","string":"série"},{"locale":"ga","country":"Irish","string":"sraith"},{"locale":"gl","country":"Galician","string":"serie"},{"locale":"gu","country":"Gujarati","string":"શ્રેણી"},{"locale":"ha","country":"Hausa","string":"jerin"},{"locale":"hi","country":"Hindi","string":"शृंखला"},{"locale":"hmn","country":"Hmong","string":"serie"},{"locale":"hr","country":"Croatian","string":"serija"},{"locale":"ht","country":"Haitian Creole","string":"seri"},{"locale":"hu","country":"Hungarian","string":"sorozat"},{"locale":"hy","country":"Armenian","string":"շարք"},{"locale":"id","country":"Indonesian","string":"seri"},{"locale":"ig","country":"Igbo","string":"usoro"},{"locale":"is","country":"Icelandic","string":"röð"},{"locale":"it","country":"Italian","string":"serie"},{"locale":"iw","country":"Hebrew","string":"סדרה"},{"locale":"ja","country":"Japanese","string":"シリーズ"},{"locale":"jw","country":"Javanese","string":"seri"},{"locale":"ka","country":"Georgian","string":"სერია"},{"locale":"kk","country":"Kazakh","string":"серия"},{"locale":"km","country":"Khmer","string":"ស៊េរី"},{"locale":"kn","country":"Kannada","string":"ಸರಣಿ"},{"locale":"ko","country":"Korean","string":"시리즈"},{"locale":"la","country":"Latin","string":"serie"},{"locale":"lo","country":"Lao","string":"ຊຸດ"},{"locale":"lt","country":"Lithuanian","string":"serija"},{"locale":"lv","country":"Latvian","string":"sērija"},{"locale":"mg","country":"Malagasy","string":"andian-dahatsoratra"},{"locale":"mi","country":"Maori","string":"raupapa"},{"locale":"mk","country":"Macedonian","string":"серија"},{"locale":"ml","country":"Malayalam","string":"പരമ്പര"},{"locale":"mn","country":"Mongolian","string":"цуврал"},{"locale":"mr","country":"Marathi","string":"मालिका"},{"locale":"ms","country":"Malay","string":"siri"},{"locale":"mt","country":"Maltese","string":"serje"},{"locale":"my","country":"Myanmar (Burmese)","string":"စီးရီး"},{"locale":"ne","country":"Nepali","string":"श्रृंखला"},{"locale":"nl","country":"Dutch","string":"serie"},{"locale":"no","country":"Norwegian","string":"serien"},{"locale":"ny","country":"Chichewa","string":"mndandanda"},{"locale":"pa","country":"Punjabi","string":"ਲੜੀ '"},{"locale":"pl","country":"Polish","string":"seria"},{"locale":"pt","country":"Portuguese","string":"série"},{"locale":"ro","country":"Romanian","string":"serie"},{"locale":"ru","country":"Russian","string":"серия"},{"locale":"si","country":"Sinhala","string":"මාලාවක්"},{"locale":"sk","country":"Slovak","string":"séria"},{"locale":"sl","country":"Slovenian","string":"serija"},{"locale":"so","country":"Somali","string":"taxane"},{"locale":"sq","country":"Albanian","string":"seri"},{"locale":"sr","country":"Serbian","string":"серија"},{"locale":"st","country":"Sesotho","string":"letoto la lihlooho"},{"locale":"su","country":"Sundanese","string":"runtuyan"},{"locale":"sv","country":"Swedish","string":"serie"},{"locale":"sw","country":"Swahili","string":"mfululizo"},{"locale":"ta","country":"Tamil","string":"தொடர்"},{"locale":"te","country":"Telugu","string":"సిరీస్"},{"locale":"tg","country":"Tajik","string":"силсила"},{"locale":"th","country":"Thai","string":"ชุด"},{"locale":"tl","country":"Filipino","string":"serye"},{"locale":"tr","country":"Turkish","string":"dizi"},{"locale":"uk","country":"Ukrainian","string":"серія"},{"locale":"ur","country":"Urdu","string":"سلسلہ"},{"locale":"uz","country":"Uzbek","string":"qator"},{"locale":"vi","country":"Vietnamese","string":"loạt"},{"locale":"yi","country":"Yiddish","string":"סעריע"},{"locale":"yo","country":"Yoruba","string":"jara"},{"locale":"zh","country":"Chinese","string":"系列"},{"locale":"zh-CN","country":"Chinese (Simplified)","string":"系列"},{"locale":"zh-TW","country":"Chinese (Traditional)","string":"系列"},{"locale":"zu","country":"Zulu","string":"uchungechunge"}] From a82aca62b7e4535621c10982d440ef02492a070b Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Mon, 8 Jul 2019 00:16:41 +0200 Subject: [PATCH 05/11] trim become regex --- packages/cinema/data/expressions/en.json | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/cinema/data/expressions/en.json b/packages/cinema/data/expressions/en.json index 607a53a0f..83defe6ea 100644 --- a/packages/cinema/data/expressions/en.json +++ b/packages/cinema/data/expressions/en.json @@ -7,15 +7,9 @@ ], "entities": [ { - "type": "trim", + "type": "regex", "name": "Serie_Or_Movie", - "conditions": [ - { - "type": "between", - "from": "a", - "to": "?" - } - ] + "regex": "film|movie|serie" } ] }, From 5358ee711ef0b6d1c8a2f442b6511711dce8c4d0 Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Tue, 9 Jul 2019 17:21:58 +0200 Subject: [PATCH 06/11] Manange different type info --- packages/cinema/data/answers/en.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/cinema/data/answers/en.json b/packages/cinema/data/answers/en.json index 6349e07e2..f128323b7 100644 --- a/packages/cinema/data/answers/en.json +++ b/packages/cinema/data/answers/en.json @@ -10,9 +10,21 @@ "nit_list":[ "%nit_title%" ], - "info":[ + "info-c":[ "%title% can be summarized as follows : %overview% " ], + "info-m":[ + + ], + "info-t":[ + + ], + "info-p":[ + + ], + "wrong_key":[ + "You have not entered any API key. If you don't have one yet you can go here and once retrieved go modify the configuration file." + ], "error":[ "Error" ] From 838be405119472cb2c37570135dbae3d360e8ce2 Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Tue, 9 Jul 2019 17:22:33 +0200 Subject: [PATCH 07/11] tmp --- packages/cinema/data/expressions/en.json | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/cinema/data/expressions/en.json b/packages/cinema/data/expressions/en.json index 607a53a0f..ff47dabd2 100644 --- a/packages/cinema/data/expressions/en.json +++ b/packages/cinema/data/expressions/en.json @@ -3,25 +3,20 @@ "recommend":{ "expressions":[ "Leon, can you recommend a ?", - "Can you recommend a ?" + "Can you recommend a ?", + "Do you have a to recommend ?" ], "entities": [ { - "type": "trim", + "type": "regex", "name": "Serie_Or_Movie", - "conditions": [ - { - "type": "between", - "from": "a", - "to": "?" - } - ] + "regex": "movie|film|serie" } ] }, "now_theatres":{ "expressions":[ - "What movies are in theatres?" + "What movies are in theatres ?" ] }, "info":{ From a084ac9b9156f943847db3f5d2acdd2bd18d2fc5 Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Tue, 9 Jul 2019 18:10:15 +0200 Subject: [PATCH 08/11] news sentences for info-c/m/t/p --- packages/cinema/data/answers/en.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/cinema/data/answers/en.json b/packages/cinema/data/answers/en.json index f128323b7..2b3df0f96 100644 --- a/packages/cinema/data/answers/en.json +++ b/packages/cinema/data/answers/en.json @@ -2,7 +2,8 @@ "cinema": { "recommend": [ "I advise you to watch %movie_title% released on %release_date%, it can be summarized as follows :

\n %summarize%

", - "I recommend you to watch %movie_title% released on %release_date%, it can be summarized as follows :

\n %summarize%

" + "I recommend you to watch %movie_title% released on %release_date%, it can be summarized as follows :

\n %summarize%

", + "One day, you should watch %movie_title% released on %release_date%, I tought it was a nice movie, I can summarize it as follows :\n %summarize% " ], "test":[ "%test%" @@ -14,13 +15,14 @@ "%title% can be summarized as follows : %overview% " ], "info-m":[ - + "%title% was released on %release_date%, it can be summarized as follows :\n %overview%.", + "I can summarize %title% as follows:\n %overview% \n did you know that it released on %release_date% ? Now you know. " ], "info-t":[ - + "%title% was released on %release_date%, it can be summarized as follows :\n %overview%." ], "info-p":[ - + "%name% was know for %maj-movie-title% it released on %release_date%." ], "wrong_key":[ "You have not entered any API key. If you don't have one yet you can go here and once retrieved go modify the configuration file." From 33db2067b7511360a0dadc943d0c486a63b0f317 Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Tue, 9 Jul 2019 18:33:08 +0200 Subject: [PATCH 09/11] new features : - info for movie/serie/people --- packages/cinema/cinema.py | 45 ++++++++++++++++++++++-- packages/cinema/data/answers/en.json | 14 ++++---- packages/cinema/data/expressions/en.json | 2 +- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/packages/cinema/cinema.py b/packages/cinema/cinema.py index a0f69c9a0..0aec79730 100644 --- a/packages/cinema/cinema.py +++ b/packages/cinema/cinema.py @@ -18,22 +18,27 @@ def load_config(func): @functools.wraps(func) def wrapper_load_config(string, entities): + # Init "payload" as dictionary payload = dict() + # Put data in payload payload["string"] = string payload["entities"] = entities # ISO 639-1 language code payload["lang"] = utils.getqueryobj()["lang"][:2] payload["today"] = dt.date.today() + # Load API key payload["API_KEY"] = utils.config('API_KEY') tmdb.API_KEY = payload["API_KEY"] + if payload["API_KEY"] == "YOUR_API_KEY": + return utils.output("end", "wrong_key", utils.translate("wrong_key")) + # Load words files who permit to check if user ask for a serie or a movie in every language with open('packages/cinema/data/words/movie.json') as json_data: payload["trl_movie"] = json.load(json_data) with open('packages/cinema/data/words/serie.json') as json_data: payload["trl_serie"] = json.load(json_data) - return func(payload) return wrapper_load_config @@ -98,7 +103,7 @@ def recommend(payload): page=ran.randint(0, 1000), language=payload["lang"], vote_average_gte=7.00) - db.insert({'type': 'rserie_request','old_id': 0, 'content': payload["movie"]}) + db.insert({'type': 'rserie_request', 'old_id': 0, 'content': payload["serie"]}) serie_nO = ran.randint(0, 20) serie = payload["serie"]["results"][serie_nO] @@ -114,6 +119,10 @@ def recommend(payload): @load_config def now_theatres(payload): + """ + Displays the list of recently released movies + """ + #Ask API about movies now_in_theatres = tmdb.Discover().movie( primary_release_date=payload["today"], language=payload["lang"]) @@ -135,9 +144,39 @@ def info(payload): data_info = tmdb.Search().collection(query=data_title, language=payload["lang"]) if data_info["total_results"] == 0: data_info = tmdb.Search().multi(query=data_title, language=payload["lang"]) + if data_info["results"][0]["media_type"] == "movie": + movie_overview = data_info["results"][0]["overview"] + movie_rdate = data_info["results"][0]["release_date"] + movie_title = data_info["results"][0]["title"] + + return utils.output("end", "info-m", utils.translate("info-m", { + "title": movie_title.title(), + "release_date": movie_rdate, + "overview": movie_overview + })) + elif data_info["results"][0]["media_type"] == "tv": + tv_overview = data_info["results"][0]["overview"] + tv_rdate = data_info["results"][0]["first_air_date"] + tv_title = data_info["results"][0]["name"] + + return utils.output("end", "info-t", utils.translate("info-t", { + "title": tv_title.title(), + "release_date": tv_rdate, + "overview": tv_overview + })) + elif data_info["results"][0]["media_type"] == "person": + people_name = data_info["results"][0]["name"] + title_know_for = data_info["results"][0]["known_for"][0]["title"] + rdate_know_for = data_info["results"][0]["known_for"][0]["release_date"] + + return utils.output("end", "info-p", utils.translate("info-p", { + "name": people_name.title(), + "release_date": rdate_know_for, + "maj-movie-title": title_know_for + })) data_overview = data_info["results"][0]["overview"] - return utils.output("end", "info", utils.translate('info', { + return utils.output("end", "info-c", utils.translate('info', { "title": data_title.title(), "overview": data_overview})) diff --git a/packages/cinema/data/answers/en.json b/packages/cinema/data/answers/en.json index 2b3df0f96..a8fe5f148 100644 --- a/packages/cinema/data/answers/en.json +++ b/packages/cinema/data/answers/en.json @@ -1,9 +1,9 @@ { "cinema": { "recommend": [ - "I advise you to watch %movie_title% released on %release_date%, it can be summarized as follows :

\n %summarize%

", - "I recommend you to watch %movie_title% released on %release_date%, it can be summarized as follows :

\n %summarize%

", - "One day, you should watch %movie_title% released on %release_date%, I tought it was a nice movie, I can summarize it as follows :\n %summarize% " + "I advise you to watch %movie_title% released on %release_date%, it can be summarized as follows :\n %summarize%", + "I recommend you to watch %movie_title% released on %release_date%, it can be summarized as follows :\n %summarize%", + "One day, you should watch %movie_title% released on %release_date%, I tought it was a nice movie, I can summarize it as follows :\n %summarize% " ], "test":[ "%test%" @@ -15,14 +15,14 @@ "%title% can be summarized as follows : %overview% " ], "info-m":[ - "%title% was released on %release_date%, it can be summarized as follows :\n %overview%.", - "I can summarize %title% as follows:\n %overview% \n did you know that it released on %release_date% ? Now you know. " + "%title% was released on %release_date%, it can be summarized as follows :\n %overview%.", + "I can summarize %title% as follows:\n %overview% \n did you know that it released on %release_date% ? Now you know. " ], "info-t":[ - "%title% was released on %release_date%, it can be summarized as follows :\n %overview%." + "%title% was released on %release_date%, it can be summarized as follows :\n %overview%." ], "info-p":[ - "%name% was know for %maj-movie-title% it released on %release_date%." + "%name% was know for %maj-movie-title% it released on %release_date%." ], "wrong_key":[ "You have not entered any API key. If you don't have one yet you can go here and once retrieved go modify the configuration file." diff --git a/packages/cinema/data/expressions/en.json b/packages/cinema/data/expressions/en.json index e48ae83a8..269b2775d 100644 --- a/packages/cinema/data/expressions/en.json +++ b/packages/cinema/data/expressions/en.json @@ -10,7 +10,7 @@ { "type": "regex", "name": "Serie_Or_Movie", - "regex": "film|movie|serie" + "regex": "film|movie|serie|show" } ] }, From 4b47285de07e1d8735de9250f78373d608a73d0e Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Thu, 18 Jul 2019 00:58:59 +0200 Subject: [PATCH 10/11] v1.0.0 tests + README --- packages/cinema/README.md | 51 +++++++++++ packages/cinema/cinema.py | 62 ++++++++----- packages/cinema/data/answers/en.json | 30 +++++-- packages/cinema/data/expressions/en.json | 11 ++- packages/cinema/test/cinema.spec.js | 109 +++++++++++++++++++++++ packages/cinema/version.txt | 2 +- 6 files changed, 229 insertions(+), 36 deletions(-) create mode 100644 packages/cinema/test/cinema.spec.js diff --git a/packages/cinema/README.md b/packages/cinema/README.md index e69de29bb..e79830e7f 100644 --- a/packages/cinema/README.md +++ b/packages/cinema/README.md @@ -0,0 +1,51 @@ +# Cinema Package + +![](https://media.discordapp.net/attachments/587078058130014240/601166722061434937/cinema.png) + +## Introduction + +This package add cinema skills for Leon. He can recommend to you series and movies, tell you wich movies are in theatre or provide information about movie, serie or people (related with cinema btw). + +### Traduction + +| Language / Module | Recommend | Movie in theatre | Info m/t/p | +| ----------------- | --------- | ---------------- | ---------- | +| EN-US | X | X | X | +| FR | | | | +| IT | | | | + + + +## Commands + + ``` +Leon, can you recommend a movie ? +or +Leon, can you recommend a serie ? + ``` + +Leon random choose an movie or an serie. + +``` +What movies are in theatres ? +``` + +Leon tell you which movies are actually in theatres. It's the **internationnal** box office, if your country have a specific day in the week for movie release he doesn't take it into account. + +``` +Can you provide information about Star Wars/Capitain Marvel/Game of Thrones/ Tom Cruz with moviedb ? +``` + +It's going to give you some information about movies collection, movie, serie or people. + +## Dev part + +As you can see on the last sentence we can specify the API, default API is c but the entity actually exist, you can use it. + + + +## Licence + +Data DB : https://www.themoviedb.org/ + +Librairie : https://pypi.org/project/tmdbsimple/ \ No newline at end of file diff --git a/packages/cinema/cinema.py b/packages/cinema/cinema.py index 0aec79730..729b354be 100644 --- a/packages/cinema/cinema.py +++ b/packages/cinema/cinema.py @@ -46,30 +46,35 @@ def wrapper_load_config(string, entities): @load_config def recommend(payload): + """ + Recommend Series or Movies. (random movies/series on movieDB with > 7 stars) + """ + # Init flags for movie and serie flag_movie = 0 flag_serie = 0 + + # Search the type of requested data (movie or serie) with regex (translate it) for item in payload["entities"]: - if item["entity"] == "Serie_Or_Movie": - word = item["sourceText"] - i = 0 - wflag = 0 - while i < 92 and wflag == 0: - if payload["trl_movie"][i]["string"] == word: - flag_movie = 1 - wflag = 1 - elif payload["trl_serie"][i]["string"] == word: - flag_serie = 1 - wflag = 1 - i = i + 1 + if item["entity"] == "Movie": + flag_movie = 1 + elif item["entity"] == "Serie": + flag_serie = 1 else: return utils.output('end', 'Error', utils.translate('Error')) - if flag_movie == 1: + # In case of the user ask strange things. + if flag_serie == 0 and flag_movie == 0 : + return utils.output("end", "not_found", utils.translate("not_found")) + + # If user request a movie + elif flag_movie == 1: + # If database exist he don't request if db.search(Query.type == 'rmovie_request'): payload["movie"] = db.search(Query.type == 'rmovie_request')[0]['content'] o_id = db.search(Query.type == 'rmovie_request')[0]['old_id'] o_id = o_id + 1 db.update({"old_id": o_id}, Query.type == 'rmovie_request') + # Remove information from database after 10 utilisations db.remove(Query.type == 'rmovie_request' and Query.old_id > 10) else: # Get an random movie with user's language @@ -77,19 +82,21 @@ def recommend(payload): page=ran.randint(0, 1000), language=payload["lang"], vote_average_gte=7.00) + # Insert JSON file in the database db.insert({'type': 'rmovie_request','old_id': 0, 'content': payload["movie"]}) + # Reach some information movie_nO = ran.randint(0, 20) movie = payload["movie"]["results"][movie_nO] movie_title = movie["title"] movie_rdate = movie["release_date"] movie_sum = movie["overview"] - return utils.output('end', 'recommend', utils.translate('recommend', { + return utils.output('end', 'recommend-m', utils.translate('recommend-m', { "movie_title": movie_title, "release_date": movie_rdate, "summarize": movie_sum})) - + # same here but with serie elif flag_serie == 1: if db.search(Query.type == 'rserie_request'): payload["serie"] = db.search(Query.type == 'rserie_request')[0]['content'] @@ -111,8 +118,8 @@ def recommend(payload): serie_rdate = serie["first_air_date"] serie_sum = serie["overview"] - return utils.output('end', 'recommend', utils.translate('recommend', { - "movie_title": serie_title, + return utils.output('end', 'recommend-t', utils.translate('recommend-t', { + "serie_title": serie_title, "release_date": serie_rdate, "summarize": serie_sum})) @@ -126,25 +133,34 @@ def now_theatres(payload): now_in_theatres = tmdb.Discover().movie( primary_release_date=payload["today"], language=payload["lang"]) - res = 'The films currently in the cinema are:
    ' + res = '
      ' for title in now_in_theatres["results"]: res = res+"
    • "+title["title"]+"
    • "+"
      " res = res + "
    " - return utils.output("end", "nit_title_list", utils.translate('nit_list', { + return utils.output("end", "nit_list", utils.translate('nit_list', { "nit_title": res })) @load_config def info(payload): + """ + Give information about movies, collections, series and peoples. + """ for item in payload["entities"]: if item["entity"] == "title": data_title = item["sourceText"] + # Search if it's an collection data_info = tmdb.Search().collection(query=data_title, language=payload["lang"]) + # If not re-ask API with multi research if data_info["total_results"] == 0: data_info = tmdb.Search().multi(query=data_title, language=payload["lang"]) - if data_info["results"][0]["media_type"] == "movie": + if data_info["total_results"] == 0: + return utils.output('end', 'not_found_title', utils.translate('not_found_title',{ + "idk_request": data_title + })) + elif data_info["results"][0]["media_type"] == "movie": movie_overview = data_info["results"][0]["overview"] movie_rdate = data_info["results"][0]["release_date"] movie_title = data_info["results"][0]["title"] @@ -174,9 +190,9 @@ def info(payload): "release_date": rdate_know_for, "maj-movie-title": title_know_for })) + else: + data_overview = data_info["results"][0]["overview"] - data_overview = data_info["results"][0]["overview"] - - return utils.output("end", "info-c", utils.translate('info', { + return utils.output("end", "info-c", utils.translate('info-c', { "title": data_title.title(), "overview": data_overview})) diff --git a/packages/cinema/data/answers/en.json b/packages/cinema/data/answers/en.json index a8fe5f148..0b4cf1df4 100644 --- a/packages/cinema/data/answers/en.json +++ b/packages/cinema/data/answers/en.json @@ -1,22 +1,27 @@ { "cinema": { - "recommend": [ - "I advise you to watch %movie_title% released on %release_date%, it can be summarized as follows :\n %summarize%", - "I recommend you to watch %movie_title% released on %release_date%, it can be summarized as follows :\n %summarize%", - "One day, you should watch %movie_title% released on %release_date%, I tought it was a nice movie, I can summarize it as follows :\n %summarize% " + "recommend-m": [ + "I advise you to watch %movie_title% released on %release_date%, it can be summarized as follows :\n %summarize%.", + "I recommend you to watch %movie_title% released on %release_date%, it can be summarized as follows :\n %summarize%.", + "One day, you should watch %movie_title% released on %release_date%, I tought it was a nice movie, I can summarize it as follows :\n %summarize%." ], + "recommend-t": [ + "I advise you to watch %serie_title% released on %release_date%, it can be summarized as follows :\n %summarize%.", + "I recommend you to watch %serie_title% released on %release_date%, it can be summarized as follows :\n %summarize%.", + "One day, you should watch %serie_title% released on %release_date%, I tought it was a nice serie, I can summarize it as follows :\n %summarize%." + ], "test":[ - "%test%" + "%test%." ], "nit_list":[ - "%nit_title%" + "The films currently in the cinema are: \n %nit_title%\n It's internationnal box office." ], "info-c":[ - "%title% can be summarized as follows : %overview% " + "%title% can be summarized as follows : %overview%." ], "info-m":[ "%title% was released on %release_date%, it can be summarized as follows :\n %overview%.", - "I can summarize %title% as follows:\n %overview% \n did you know that it released on %release_date% ? Now you know. " + "I can summarize %title% as follows:\n %overview% \n did you know that it released on %release_date% ? Now you know." ], "info-t":[ "%title% was released on %release_date%, it can be summarized as follows :\n %overview%." @@ -28,7 +33,14 @@ "You have not entered any API key. If you don't have one yet you can go here and once retrieved go modify the configuration file." ], "error":[ - "Error" + "Error." + ], + "not_found":[ + "I don't know this word." + ], + "not_found_title":[ + "I don't know \"%idk_request%\".", + "I found nothing about \"%idk_request%\"." ] } } diff --git a/packages/cinema/data/expressions/en.json b/packages/cinema/data/expressions/en.json index 269b2775d..04628ecc5 100644 --- a/packages/cinema/data/expressions/en.json +++ b/packages/cinema/data/expressions/en.json @@ -9,9 +9,14 @@ "entities": [ { "type": "regex", - "name": "Serie_Or_Movie", - "regex": "film|movie|serie|show" - } + "name": "Movie", + "regex": "film|movie" + }, + { + "type": "regex", + "name": "Serie", + "regex": "serie|show" + } ] }, "now_theatres":{ diff --git a/packages/cinema/test/cinema.spec.js b/packages/cinema/test/cinema.spec.js new file mode 100644 index 000000000..496a5403c --- /dev/null +++ b/packages/cinema/test/cinema.spec.js @@ -0,0 +1,109 @@ +'use strict' + +describe('cinema:cinema', async () => { + test('[Feature] Recommend movie', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you recommend a movie ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['recommend-m']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Feature] Recommend serie', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you recommend a serie ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['recommend-t']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Error management] Recommend failed error message', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you recommend a blublu ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['not_found']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Feature] Request information about an movie', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you provide information about Captain Marvel ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['info-m']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Feature] Request information about an serie or tv show', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you provide information about Big Bang Theory ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['info-t']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Feature] Request information about an actor/realisator/productor', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you provide information about Tom Cruz ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['info-p']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Feature] Request information about an collection of movie', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you provide information about Star Wars ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['info-c']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Error management] Info failed error message', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('Can you provide information about blublu ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['not_found_title']) + }) +}) + +describe('cinema:cinema', async () => { + test('[Feature] List of movies actually in theatres (internationnal box office)', async () => { + global.nlu.brain.execute = jest.fn() + await global.nlu.process('What movies are in theatres ?') + + const [obj] = global.nlu.brain.execute.mock.calls + await global.brain.execute(obj[0]) + + expect(global.brain.finalOutput.codes).toIncludeSameMembers(['nit_list']) + }) +}) diff --git a/packages/cinema/version.txt b/packages/cinema/version.txt index 77d6f4ca2..3eefcb9dd 100644 --- a/packages/cinema/version.txt +++ b/packages/cinema/version.txt @@ -1 +1 @@ -0.0.0 +1.0.0 From 35487e418ad1390f7dd8ac94550892151fca9a47 Mon Sep 17 00:00:00 2001 From: gnouf1 Date: Thu, 18 Jul 2019 01:00:48 +0200 Subject: [PATCH 11/11] Update README.md --- packages/cinema/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cinema/README.md b/packages/cinema/README.md index e79830e7f..f94806130 100644 --- a/packages/cinema/README.md +++ b/packages/cinema/README.md @@ -30,7 +30,7 @@ Leon random choose an movie or an serie. What movies are in theatres ? ``` -Leon tell you which movies are actually in theatres. It's the **internationnal** box office, if your country have a specific day in the week for movie release he doesn't take it into account. +Leon tell you which movies are actually in theatres. It's the **international** box office, if your country have a specific day in the week for movie release he doesn't take it into account. ``` Can you provide information about Star Wars/Capitain Marvel/Game of Thrones/ Tom Cruz with moviedb ? @@ -40,7 +40,7 @@ It's going to give you some information about movies collection, movie, serie or ## Dev part -As you can see on the last sentence we can specify the API, default API is c but the entity actually exist, you can use it. +As you can see on the last sentence we can specify the API, default API is The Movie DB (TMDB) but the entity actually exist, you can use it. @@ -48,4 +48,4 @@ As you can see on the last sentence we can specify the API, default API is c but Data DB : https://www.themoviedb.org/ -Librairie : https://pypi.org/project/tmdbsimple/ \ No newline at end of file +Librairie : https://pypi.org/project/tmdbsimple/