Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cinema #116

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions bridges/python/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ requests = "==2.21.0"
pytube = "==9.5.0"
tinydb = "==3.9.0"
beautifulsoup4 = "==4.7.1"
tmdbsimple = "==2.2.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is quite old, before we merge, we should use the latest versions of the dependencies used in this package.
Currently the latest version of tmdbsimple is 2.8.0.


[dev-packages]
14 changes: 10 additions & 4 deletions bridges/python/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added packages/Pipfile
Empty file.
51 changes: 51 additions & 0 deletions packages/cinema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Cinema Package

![](https://media.discordapp.net/attachments/587078058130014240/601166722061434937/cinema.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use external ressources for images, we should store them ourselves.
Also there is no alt, even if it's only in markdown etc, we should still follow the best practices, and set the alt attributes the thing between [].


## 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 **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 ?
```

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 The Movie DB (TMDB) but the entity actually exist, you can use it.



## Licence

Data DB : https://www.themoviedb.org/

Librairie : https://pypi.org/project/tmdbsimple/
Empty file added packages/cinema/__init__.py
Empty file.
198 changes: 198 additions & 0 deletions packages/cinema/cinema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import utils
import tmdbsimple as tmdb
import functools
import random as ran
import datetime as dt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you renaming :

  • tmdbsimple as tmdb
  • random as ran
  • datetime as dt

We should keep the default, it's a lot clearer, and as said, I don't think abbreviations in the code is great.

import json

# Package database
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using useless comments.

db = utils.db()['db']

# Query
Query = utils.db()['query']()


def load_config(func):
@functools.wraps(func)
def wrapper_load_config(string, entities):
# Init "payload" as dictionary
payload = dict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, payload is configuration right ?
Maybe we could rename it config or configuration and why do you initialize with dict(), you could simply do like this :

config = {}

Also as said before, we should avoid using useless comments.

# 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


@load_config
def recommend(payload):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should split this fiunctions in multiple small functions, the code is quite hard to understand if there weren't the comments, but it would be better to make it comprehensible without comments.

"""
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"] == "Movie":
flag_movie = 1
elif item["entity"] == "Serie":
flag_serie = 1
else:
return utils.output('end', 'Error', utils.translate('Error'))

# 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
payload["movie"] = tmdb.Discover().movie(
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-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']
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["serie"]})

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-t', utils.translate('recommend-t', {
"serie_title": serie_title,
"release_date": serie_rdate,
"summarize": serie_sum}))


@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"])
res = '<ul>'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of res we could name it result.

for title in now_in_theatres["results"]:
res = res+"<li>"+title["title"]+"</li>"+"<br/>"
res = res + "</ul>"

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["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"]

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
}))
else:
data_overview = data_info["results"][0]["overview"]

return utils.output("end", "info-c", utils.translate('info-c', {
"title": data_title.title(),
"overview": data_overview}))
6 changes: 6 additions & 0 deletions packages/cinema/config/config.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cinema": {
"API_KEY": "YOUR_API_KEY",
"options": {}
}
}
46 changes: 46 additions & 0 deletions packages/cinema/data/answers/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"cinema": {
"recommend-m": [
"I advise you to watch <b>%movie_title%</b> released on %release_date%, it can be summarized as follows :\n %summarize%.",
"I recommend you to watch <b>%movie_title%</b> released on %release_date%, it can be summarized as follows :\n %summarize%.",
"One day, you should watch <b>%movie_title%</b> 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 <b>%serie_title%</b> released on %release_date%, it can be summarized as follows :\n %summarize%.",
"I recommend you to watch <b>%serie_title%</b> released on %release_date%, it can be summarized as follows :\n %summarize%.",
"One day, you should watch <b>%serie_title%</b> released on %release_date%, I tought it was a nice serie, I can summarize it as follows :\n %summarize%."
],
"test":[
"%test%."
],
"nit_list":[
"The films currently in the cinema are: \n %nit_title%\n It's internationnal box office."
],
"info-c":[
"<b>%title%</b> can be summarized as follows : %overview%."
],
"info-m":[
"<b>%title%</b> was released on %release_date%, it can be summarized as follows :\n %overview%.",
"I can summarize <b>%title%</b> as follows:\n %overview% \n did you know that it released on %release_date% ? Now you know."
],
"info-t":[
"<b>%title%</b> was released on %release_date%, it can be summarized as follows :\n %overview%."
],
"info-p":[
"<b>%name%</b> 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 <a href=\"https://www.themoviedb.org/documentation/api\">here</a> and once retrieved go modify the configuration file."
],
"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%\"."
]
}
}
Loading