Skip to content

Commit

Permalink
Version 0.0.3
Browse files Browse the repository at this point in the history
- Top Netlfix, HBO and Filmin
- Recommendation from Netflix, HBO or Filmin
- Fixed errors
  • Loading branch information
sergiormb committed Jun 10, 2017
1 parent 8752389 commit e94355f
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 14 deletions.
12 changes: 10 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ Changelog
=========


v0.0.3 (10-06-2017)
*******************

- Top Netlfix, HBO and Filmin
- Recommendation from Netflix, HBO or Filmin
- Fixed errors


v0.0.2 (31-05-2017)
-------------------
*******************

- Search movies by title, year, director or cast.
- Get the filmaffinity top and search by year
- Get the premieres top


v0.0.1 (29-05-2017)
-------------------
*******************

- Initial release.
46 changes: 46 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ top_filmaffinity
+-----------+----------+--------+-----------------------------------+
| to_year | False | String | Search end date |
+-----------+----------+--------+-----------------------------------+
| top | False | Integer| Number of elements |
+-----------+----------+--------+-----------------------------------+

- Example

Expand All @@ -148,17 +150,61 @@ top_filmaffinity
top_premieres
*************

+-----------+----------+--------+-----------------------------------+
| Parameter | Required | Type | Description |
+===========+==========+========+===================================+
| top | False | Integer| Number of elements |
+-----------+----------+--------+-----------------------------------+

- Example

.. code-block:: python
movies = service.top_premieres()
top_netflix, top_hbo, top_filmin
********************************

+-----------+----------+--------+-----------------------------------+
| Parameter | Required | Type | Description |
+===========+==========+========+===================================+
| top | False | Integer| Number of elements |
+-----------+----------+--------+-----------------------------------+

- Example

.. code-block:: python
movies = service.top_netflix()
movies = service.top_hbo(top=5)
movies = service.top_filmin()
recommend HBO, Netflix, Filmin
******************************

- Example

.. code-block:: python
movies = service.recommend_netflix()
movies = service.recommend_hbo()
movies = service.recommend_filmin()
Changelog
=========


v0.0.3 (10-06-2017)
*******************

- Top Netlfix, HBO and Filmin
- Recommendation from Netflix, HBO or Filmin
- Fixed errors


v0.0.2 (31-05-2017)
*******************

Expand Down
47 changes: 45 additions & 2 deletions USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ Usage
=====

language
******
********

- Spanish: 'es'
- USA | UK: 'en'
- USA, UK: 'en'
- México: 'mx'
- Argentina: 'ar'
- Chile: 'cl'
Expand Down Expand Up @@ -73,6 +73,8 @@ top_filmaffinity
+-----------+----------+--------+-----------------------------------+
| to_year | False | String | Search end date |
+-----------+----------+--------+-----------------------------------+
| top | False | Integer| Number of elements |
+-----------+----------+--------+-----------------------------------+

- Example

Expand All @@ -85,9 +87,50 @@ top_filmaffinity
top_premieres
*************

+-----------+----------+--------+-----------------------------------+
| Parameter | Required | Type | Description |
+===========+==========+========+===================================+
| top | False | Integer| Number of elements |
+-----------+----------+--------+-----------------------------------+

- Example

.. code-block:: python
movies = service.top_premieres()
top_netflix, top_hbo, top_filmin
********************************

+-----------+----------+--------+-----------------------------------+
| Parameter | Required | Type | Description |
+===========+==========+========+===================================+
| top | False | Integer| Number of elements |
+-----------+----------+--------+-----------------------------------+

- Example

.. code-block:: python
movies = service.top_netflix()
movies = service.top_hbo(top=5)
movies = service.top_filmin()
recommend HBO, Netflix, Filmin
******************************

+-----------+----------+--------+-----------------------------------+
| Parameter | Required | Type | Description |
+===========+==========+========+===================================+
| top | False | Integer| Number of elements |
+-----------+----------+--------+-----------------------------------+

- Example

.. code-block:: python
movies = service.recommend_netflix()
movies = service.recommend_hbo()
movies = service.recommend_filmin()
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.0.2'
version = u'0.0.3'
# The full version, including alpha/beta/rc tags.
release = u'0.0.2'
release = u'0.0.3'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
100 changes: 95 additions & 5 deletions python_filmaffinity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import requests
import random
from bs4 import BeautifulSoup

FIELDS_MOVIE = ['title', 'id']
Expand Down Expand Up @@ -29,6 +30,11 @@ def _get_title_by_search(self, soup):
title = soup.find('div', {'class': 'mc-title'})
return title.get_text() if title else None

def _get_title_by_top(self, soup):
title_cell = soup.find('div', {'class': 'mc-right'})
title = title_cell.find('h3')
return title.get_text() if title else None

def _get_year(self, soup):
year_cell = soup.find("dd", {"itemprop": 'datePublished'})
year = year_cell.get_text()
Expand Down Expand Up @@ -182,7 +188,7 @@ def search(self, **kwargs):
movies.append(movie)
return movies

def top_filmaffinity(self, **kwargs):
def top_filmaffinity(self, top=10, **kwargs):
"""Return a list with the top filmaffinity movies.
Args:
Expand All @@ -207,7 +213,7 @@ def top_filmaffinity(self, **kwargs):
page = requests.get(url)
soup = BeautifulSoup(page.text, "html.parser")
movies_cell = soup.find_all("div", {"class": 'movie-card'})
for cell in movies_cell:
for cell in movies_cell[:top]:
movie = {
'title': self._get_title_by_search(cell),
'directors': self._get_directors_by_search(cell),
Expand All @@ -217,7 +223,7 @@ def top_filmaffinity(self, **kwargs):
movies.append(movie)
return movies

def top_premieres(self):
def top_premieres(self, top=10):
"""Return a list with the top filmaffinity movies.
Args:
Expand All @@ -232,12 +238,96 @@ def top_premieres(self):
page = requests.get(url)
soup = BeautifulSoup(page.text, "html.parser")
movies_cell = soup.find_all("div", {"class": 'movie-card'})
for cell in movies_cell:
for cell in movies_cell[:top]:
movie = {
'title': self._get_title_by_search(cell),
'title': self._get_title_by_top(cell),
'directors': self._get_directors_by_search(cell),
'id': str(cell['data-movie-id']),
'poster': self._get_poster_by_search(cell),
}
movies.append(movie)
return movies

def _top_service(self, top, service):
movies = []
if self.lang == 'es':
top = 40 if top > 40 else top
url = self.url + 'topcat.php?id=' + service
page = requests.get(url)
soup = BeautifulSoup(page.text, "html.parser")
movies_cell = soup.find_all("div", {"class": 'movie-card'})
for cell in movies_cell[:top]:
movie = {
'title': self._get_title_by_top(cell),
'directors': self._get_directors_by_search(cell),
'id': str(cell['data-movie-id']),
'poster': self._get_poster_by_search(cell),
}
movies.append(movie)
return movies

def top_netflix(self, top=10):
"""Return a list with the top netflix movies.
Returns:
TYPE: Lis with movies data
"""
movies = self._top_service(top, 'new_netflix')
return movies

def top_hbo(self, top=10):
"""Return a list with the top hbo movies.
Returns:
TYPE: Lis with movies data
"""
movies = self._top_service(top, 'new_hbo_es')
return movies

def top_filmin(self, top=10):
"""Return a list with the top filmin movies.
Returns:
TYPE: Lis with movies data
"""
movies = self._top_service(top, 'new_filmin')
return movies

def _recommend(self, service):
movie = {}
if self.lang == 'es':
url = self.url + 'topcat.php?id=' + service
page = requests.get(url)
soup = BeautifulSoup(page.text, "html.parser")
movies_cell = soup.find_all("div", {"class": 'movie-card'})
cell = random.choice(movies_cell)
id = str(cell['data-movie-id'])
movie = self._get_movie_by_id(id)
return movie

def recommend_netflix(self):
"""Return a movie random in Netflix.
Returns:
TYPE: Movie data
"""
movies = self._recommend('new_netflix')
return movies

def recommend_hbo(self):
"""Return a movie random in HBO.
Returns:
TYPE: Movie data
"""
movies = self._recommend('new_hbo_es')
return movies

def recommend_filmin(self):
"""Return a movie random in Filmin.
Returns:
TYPE: Movie data
"""
movies = self._recommend('new_filmin')
return movies
2 changes: 1 addition & 1 deletion __meta__.py → python_filmaffinity/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__summary__ = 'Python wrapper for Filmaffinity'
__url__ = 'https://github.com/sergiormb/python_filmaffinityy'

__version__ = '0.0.2'
__version__ = '0.0.3'

__install_requires__ = [
'requests>=2.0.1',
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read(fname):


meta = {}
exec(read('__meta__.py'), meta)
exec(read('python_filmaffinity/__meta__.py'), meta)

setup(
name=meta['__title__'],
Expand All @@ -34,7 +34,7 @@ def read(fname):
install_requires=meta['__install_requires__'],
zip_safe=False,
# use the URL to the github repo
download_url='https://github.com/sergiormb/python_filmaffinity/tarball/0.0.2',
download_url='https://github.com/sergiormb/python_filmaffinity/tarball/0.0.3',
keywords='filmaffinity movies films',
classifiers=[
'Environment :: Web Environment',
Expand Down
28 changes: 28 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_top_filmaffinity(self):
def test_top_premieres(self):
movies = self.service.top_premieres()
self.assertNotEqual(0, len(movies))
self.assertNotEqual(len(movies[0]['title']), None)

def test_top_filmaffinity_years(self):
movies = self.service.top_filmaffinity(from_year='2010', to_year='2011')
Expand All @@ -44,3 +45,30 @@ def test_get_movie_title(self):
def test_get_movie_title_future(self):
movie = self.service.get_movie(title='Batman')
self.assertEqual(movie['rating'], None)

def test_top_netflix(self):
movies = self.service.top_netflix(top=10)
self.assertEqual(len(movies), 10)
self.assertNotEqual(len(movies[0]['title']), None)

def test_top_hbo(self):
movies = self.service.top_hbo(top=10)
self.assertEqual(len(movies), 10)
self.assertNotEqual(len(movies[0]['title']), None)

def test_top_filmin(self):
movies = self.service.top_filmin(top=10)
self.assertEqual(len(movies), 10)
self.assertNotEqual(len(movies[0]['title']), None)

def test_recommend_netflix(self):
movie = self.service.recommend_netflix()
self.assertNotEqual(len(movie['title']), None)

def test_recommend_hbo(self):
movie = self.service.recommend_hbo()
self.assertNotEqual(len(movie['title']), None)

def test_recommend_filmin(self):
movie = self.service.recommend_filmin()
self.assertNotEqual(len(movie['title']), None)

0 comments on commit e94355f

Please sign in to comment.