diff --git a/.coverage b/.coverage new file mode 100644 index 0000000..2b9bbab --- /dev/null +++ b/.coverage @@ -0,0 +1 @@ +!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/sergiormb/python-filmaffinity/root-dir/python_filmaffinity/__init__.py":[2,3,5,6,9,11,13,19,20,21,23,24,25,26,28,29,30,32,33,34,35,37,38,39,40,42,43,44,45,46,49,51,52,53,54,55,58,60,61,62,63,64,65,66,68,69,70,71,72,73,75,76,77,78,79,80,81,83,84,85,86,87,90,92,93,94,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,114,116,117,118,119,121,122,123,124,125,126,127,128,129,131,140,141,142,143,144,146,147,149,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,182,183,185,195,196,197,198,199,200,201,202,203,204,206,207,208,209,210,211,212,213,214,215,217,218,220,230,231,232,233,234,235,236,237,238,239,240,242,243]}} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a084d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ + +*.pyc + +\.cache/v/cache/ + +dist/ + +build/ + +build/lib.linux-x86_64-2.7/ + +htmlcov/ + +docs/_static/ + +docs/_build/ + +docs/_templates/ + +python_filmaffinity.egg-info/ + +.eggs/ + +test.py \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..53653fc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +sudo: false +language: python +python: + - "2.7" + - "3.4" + - "3.5" +install: + - make travisci-install +script: + - make travisci-test + - coverage run --source python_filmaffinity setup.py test +after_success: + - coveralls diff --git a/AUTHORS.md b/AUTHORS.md new file mode 100644 index 0000000..5a44d74 --- /dev/null +++ b/AUTHORS.md @@ -0,0 +1,5 @@ +## Authors + +### Lead + +- Sergio Pino, sergiormb88@gmail.com, [sergiormb.github.io](https://sergiormb.github.io/) diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..101d7a5 --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,6 @@ +## Changelog + + +### v0.0.1 (29-05-2017) + +- Initial release. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..f2d8b76 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,23 @@ +## License + +The MIT License (MIT) + +Copyright (c) 2014 Derrick Gilland + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b3c12f9 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include LICENSE.md README.md CHANGES.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f77b58e --- /dev/null +++ b/README.md @@ -0,0 +1,122 @@ +# Python Filmaffinity +This is a simple python scraping for the Filmaffinity. + +[![Build Status](https://travis-ci.org/sergiormb/python_filmaffinity.svg?branch=master)](https://travis-ci.org/sergiormb/python_filmaffinity) +[![Coverage Status](https://coveralls.io/repos/github/sergiormb/python_filmaffinity/badge.svg?branch=master)](https://coveralls.io/github/sergiormb/python_filmaffinity?branch=master) +[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/sergiormb/python_filmaffinity/blob/master/LICENSE.md) +[![PyPI](https://img.shields.io/pypi/pyversions/Django.svg)](https://pypi.python.org/pypi/python_filmaffinity/) +[![Documentation Status](https://readthedocs.org/projects/python-filmaffinity/badge/?version=latest)](http://python-filmaffinity.readthedocs.io/en/latest/?badge=latest) + +## Installation +#### Pip +- `pip install python_filmaffinity` + +#### From Source +- `git clone git@github.com:sergiormb/python_filmaffinity.git` +- `cd python_filmaffinity` +- `python setup.py install` + +#### Requirements +- `requests >= 2.0.1` +- `bs4 >= 0.0.1` + +## Example +```python +>>> import python_filmaffinity +>>> service = python_filmaffinity.Filmaffinity() +>>> movie = service.get_movie(title='Celda 211') +>>> movie['title'] +Celda 211 +>>> movie['rating'] +7.7 +>>> movie['directors'] +['Daniel Monzón'] +>>> movie['actors'] +['Luis Tosar', 'Alberto Ammann', 'Antonio Resines', 'Carlos Bardem', 'Marta Etura', 'Vicente Romero', 'Manuel Morón', 'Manolo Solo', 'Fernando Soto', 'Luis Zahera', 'Patxi Bisquert', 'Félix Cubero', 'Josean Bengoetxea', 'Juan Carlos Mangas', 'Jesús Carroza'] +``` + +## Usage +- ### search +| Parameter | Required | Type | Description | +|-----------|----------|--------|-----------------------------------| +| title | False | String | Search for the title of the movie | +| cast | False | String | Search movies by actor | +| director | False | String | Search movies by the director | +| from_year | False | String | Search start date | +| to_year | False | String | Search end date | +##### Example +```python +>>> movies = service.search(cast='Nicolas Cage') +``` + +- ### get_movie +| Parameter | Required | Type | Description | +|-----------|----------|--------|-----------------------------------| +| id | False | String | Filmaffinity id | +| title | False | String | Get movie by title | +##### Example +```python +>>> movies = service.get_movie(title='Avatar') +>>> movies = service.get_movie(id='495280') +``` + +- ### top_filmaffinity +| Parameter | Required | Type | Description | +|-----------|----------|--------|-----------------------------------| +| from_year | False | String | Search start date | +| to_year | False | String | Search end date | +##### Example +```python +>>> movies = service.top_filmaffinity() +>>> movies = service.top_filmaffinity(from_year=2010, to_year=2011) +``` + +- ### top_premieres +##### Example +```python +>>> movies = service.top_premieres() +``` + +## Changelog + +### v0.0.2 (29-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. + + +## License + +The MIT License (MIT) + +Copyright (c) 2014 Derrick Gilland + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +## Authors + +### Lead + +- Sergio Pino, sergiormb88@gmail.com, [sergiormb.github.io](https://sergiormb.github.io/) diff --git a/__meta__.py b/__meta__.py new file mode 100644 index 0000000..83258b4 --- /dev/null +++ b/__meta__.py @@ -0,0 +1,18 @@ +"""Project metadata. +""" + +__title__ = 'python_filmaffinity' +__summary__ = 'Python wrapper for Filmaffinity' +__url__ = 'https://github.com/sergiormb/python_filmaffinityy' + +__version__ = '0.0.1' + +__install_requires__ = [ + 'requests>=2.0.1', + 'bs4>=0.0.1' +] + +__author__ = 'sergiormb' +__email__ = 'sergiormb88@gmail.com' + +__license__ = 'MIT License' diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..be2a7d9 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = python -msphinx +SPHINXPROJ = python_filmaffinity +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..ed345a0 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- +# +# python_filmaffinity documentation build configuration file, created by +# sphinx-quickstart on Mon May 29 20:23:17 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) +import sphinx_rtd_theme +from recommonmark.parser import CommonMarkParser + + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + + +source_parsers = { + '.md': CommonMarkParser, +} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.md' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'python_filmaffinity' +copyright = u'2017, Sergio Pino' +author = u'Sergio Pino' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'0.0.1' +# The full version, including alpha/beta/rc tags. +release = u'0.0.1' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# + +html_theme = 'sphinx_rtd_theme' +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = 'python_filmaffinitydoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'python_filmaffinity.tex', u'python\\_filmaffinity Documentation', + u'Sergio Pino', 'manual'), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'python_filmaffinity', u'python_filmaffinity Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'python_filmaffinity', u'python_filmaffinity Documentation', + author, 'python_filmaffinity', 'One line description of project.', + 'Miscellaneous'), +] + + + diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..639f0da --- /dev/null +++ b/docs/index.md @@ -0,0 +1,122 @@ +# Python Filmaffinity +This is a simple python scraping for the Filmaffinity. + +[![Build Status](https://travis-ci.org/sergiormb/python_filmaffinity.svg?branch=master)](https://travis-ci.org/sergiormb/python_filmaffinity) +[![Coverage Status](https://coveralls.io/repos/github/sergiormb/python_filmaffinity/badge.svg?branch=master)](https://coveralls.io/github/sergiormb/python_filmaffinity?branch=master) +[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/sergiormb/python_filmaffinity/blob/master/LICENSE.md) +[![PyPI](https://img.shields.io/pypi/pyversions/Django.svg)](https://pypi.python.org/pypi/python_filmaffinity/) +[![Documentation Status](https://readthedocs.org/projects/python-filmaffinity/badge/?version=latest)](http://python-filmaffinity.readthedocs.io/en/latest/?badge=latest) + +## Installation +#### Pip +- `pip install python_filmaffinity` + +#### From Source +- `git clone git@github.com:sergiormb/python_filmaffinity.git` +- `cd python_filmaffinity` +- `python setup.py install` + +#### Requirements +- `requests >= 2.0.1` +- `bs4 >= 0.0.1` + +## Example +```python +>>> import python_filmaffinity +>>> service = python_filmaffinity.Filmaffinity() +>>> movie = service.get_movie(title='Celda 211') +>>> movie['title'] +Celda 211 +>>> movie['rating'] +7.7 +>>> movie['directors'] +['Daniel Monzón'] +>>> movie['actors'] +['Luis Tosar', 'Alberto Ammann', 'Antonio Resines', 'Carlos Bardem', 'Marta Etura', 'Vicente Romero', 'Manuel Morón', 'Manolo Solo', 'Fernando Soto', 'Luis Zahera', 'Patxi Bisquert', 'Félix Cubero', 'Josean Bengoetxea', 'Juan Carlos Mangas', 'Jesús Carroza'] +``` + +## Usage +### search +| Parameter | Required | Type | Description | +|-----------|----------|--------|-----------------------------------| +| title | False | String | Search for the title of the movie | +| cast | False | String | Search movies by actor | +| director | False | String | Search movies by the director | +| from_year | False | String | Search start date | +| to_year | False | String | Search end date | +##### Example +```python +>>> movies = service.search(cast='Nicolas Cage') +``` + +### get_movie +| Parameter | Required | Type | Description | +|-----------|----------|--------|-----------------------------------| +| id | False | String | Filmaffinity id | +| title | False | String | Get movie by title | +##### Example +```python +>>> movies = service.get_movie(title='Avatar') +>>> movies = service.get_movie(id='495280') +``` + +### top_filmaffinity +| Parameter | Required | Type | Description | +|-----------|----------|--------|-----------------------------------| +| from_year | False | String | Search start date | +| to_year | False | String | Search end date | +##### Example +```python +>>> movies = service.top_filmaffinity() +>>> movies = service.top_filmaffinity(from_year=2010, to_year=2011) +``` + +### top_premieres +##### Example +```python +>>> movies = service.top_premieres() +``` + +## Changelog + +### v0.0.2 (29-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. + + +## License + +The MIT License (MIT) + +Copyright (c) 2014 Derrick Gilland + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +## Authors + +### Lead + +- Sergio Pino, sergiormb88@gmail.com, [sergiormb.github.io](https://sergiormb.github.io/) diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..a2c1cca --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=python -msphinx +) +set SOURCEDIR=. +set BUILDDIR=_build +set SPHINXPROJ=python_filmaffinity + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The Sphinx module was not found. Make sure you have Sphinx installed, + echo.then set the SPHINXBUILD environment variable to point to the full + echo.path of the 'sphinx-build' executable. Alternatively you may add the + echo.Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/makefile b/makefile new file mode 100644 index 0000000..61fe339 --- /dev/null +++ b/makefile @@ -0,0 +1,102 @@ +## +# Variables +## + +ENV_NAME = env +ENV_ACT = . env/bin/activate; +PIP = $(ENV_NAME)/bin/pip +PYTEST_ARGS = --doctest-modules -v -s +PYTEST_TARGET = python_filmaffinity +COVERAGE_ARGS = --cov-config setup.cfg --cov-report term-missing --cov +COVERAGE_TARGET = python_filmaffinity + + +## +# Targets +## + +.PHONY: build +build: clean install + +.PHONY: clean +clean: clean-env clean-files + +.PHONY: clean-env +clean-env: + rm -rf $(ENV_NAME) + +.PHONY: clean-files +clean-files: + rm -rf .tox + rm -rf .coverage + find . -name \*.pyc -type f -delete + find . -name \*.test.db -type f -delete + find . -depth -name __pycache__ -type d -exec rm -rf {} \; + rm -rf dist *.egg* build + +.PHONY: install +install: + rm -rf $(ENV_NAME) + virtualenv --no-site-packages $(ENV_NAME) + $(PIP) install -r requirements.txt + +.PHONY: test +test: pep8 pytest + +.PHONY: pytest +pytest: + $(ENV_ACT) py.test $(PYTEST_ARGS) $(COVERAGE_ARGS) $(COVERAGE_TARGET) $(PYTEST_TARGET) + +.PHONY: test-full +test-full: pylint-errors test-setuppy clean-files + +.PHONY: test-setuppy +test-setuppy: + python setup.py test + + +.PHONY: lint +lint: pylint pep8 + +.PHONY: pep8 +pep8: + $(ENV_ACT) pep8 $(PYTEST_TARGET) + +.PHONY: pylint +pylint: + $(ENV_ACT) pylint $(COVERAGE_TARGET) + +.PHONY: pylint-errors +pylint-errors: + $(ENV_ACT) pylint -E $(COVERAGE_TARGET) + +.PHONY: release +release: + $(ENV_ACT) python setup.py sdist bdist_wheel + $(ENV_ACT) twine upload dist/* + rm -rf dist *.egg* build + + +.PHONY: docs +docs: + rm -r docs/_build + $(ENV_ACT) cd docs; make doctest + $(ENV_ACT) cd docs; make html + +.PHONY: serve-docs +serve-docs: + cd docs/_build/html; python2 -m SimpleHTTPServer 8000 + +## +# TravisCI +## + +.PHONY: travisci-install +travisci-install: + pip install -r requirements.txt + +.PHONY: travisci-test +travisci-test: + pep8 $(PYTEST_TARGET) + pylint -E $(COVERAGE_TARGET) + pytest tests/test.py diff --git a/python_filmaffinity/.gitignore b/python_filmaffinity/.gitignore new file mode 100644 index 0000000..7f0bfa3 --- /dev/null +++ b/python_filmaffinity/.gitignore @@ -0,0 +1,101 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ \ No newline at end of file diff --git a/python_filmaffinity/__init__.py b/python_filmaffinity/__init__.py new file mode 100644 index 0000000..c574003 --- /dev/null +++ b/python_filmaffinity/__init__.py @@ -0,0 +1,243 @@ +# -*- coding: utf-8 -*- +import requests +from bs4 import BeautifulSoup + +FIELDS_MOVIE = ['title', 'id'] +FIELDS_TYPE = ['title', 'director', 'cast'] + + +class Filmaffinity: + + base_url = 'https://www.filmaffinity.com/' + + def __init__(self, lang='es'): + """Init the search service. + + Args: + lang (str, optional): Language of the page + """ + self.lang = lang + self.url = self.base_url + self.lang + '/' + self.url_film = self.url + 'film' + + def _get_title(self, soup): + name_cell = soup.find("span", {"itemprop": 'name'}) + name = name_cell.get_text() + return name + + def _get_title_by_search(self, soup): + title = soup.find('div', {'class': 'mc-title'}) + 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() + return year + + def _get_description(self, soup): + description_cell = soup.find("dd", {"itemprop": 'description'}) + description = description_cell.get_text() + return description + + def _get_rating(self, soup): + rating = soup.find("div", {"id": 'movie-rat-avg'}) + if rating: + try: + rating = float(rating['content']) + except ValueError: + rating = None + return rating + + def _get_number_of_votes(self, soup): + votes = soup.find("span", {"itemprop": 'ratingCount'}) + if votes: + try: + votes = int(votes['content']) + except ValueError: + votes = None + return votes + + def _get_directors(self, soup): + directors = [] + directors_cell = soup.find_all("span", {"class": 'director'}) + for director_cell in directors_cell: + director = director_cell.find("span", {"itemprop": 'name'}) + directors.append(director.get_text()) + return directors + + def _get_directors_by_search(self, soup): + directors = [] + director_cell = soup.find('div', {'class': 'credits'}) + director_cell = director_cell.find('span', {'class': 'nb'}) + directors.append(director_cell.get_text()) + return directors if directors else None + + def _get_actors(self, soup): + actors = [] + actors_cell = soup.find_all("span", {"itemprop": 'actor'}) + for actor_cell in actors_cell: + actor = actor_cell.find("span", {"itemprop": 'name'}) + actors.append(actor.get_text()) + return actors + + def _get_poster(self, soup): + image = soup.find("img", {"itemprop": 'image'}) + if image: + try: + image = str(image['src']) + except ValueError: + image = None + return image + + def _get_poster_by_search(self, soup): + poster = soup.find('div', {'class': 'mc-poster'}) + poster_img = poster.find('img') + return poster_img['src'] + + def _get_movie_by_id(self, id): + movie = {} + page = requests.get(self.url_film + str(id) + '.html') + soup = BeautifulSoup(page.text, "html.parser") + exist = soup.find_all("div", {"class": 'z-movie'}) + if exist: + movie = { + 'title': self._get_title(soup), + 'year': self._get_year(soup), + 'rating': self._get_rating(soup), + 'votes': self._get_number_of_votes(soup), + 'description': self._get_description(soup), + 'directors': self._get_directors(soup), + 'actors': self._get_actors(soup), + 'poster': self._get_poster(soup), + } + + return movie + + def _get_movie_by_args(self, key, value): + movie = {} + if key in FIELDS_MOVIE: + options = '&stype[]=%s' % key + url = self.url + 'advsearch.php?stext=' + \ + str(value) + options + page = requests.get(url) + soup = BeautifulSoup(page.text, "html.parser") + movies_cell = soup.find_all("div", {"class": 'movie-card-1'}) + if movies_cell: + cell = movies_cell[0] + id = str(cell['data-movie-id']) + movie = self._get_movie_by_id(id) + return movie + + def get_movie(self, **kwargs): + """Return a dictionary with the data of the movie. + + Args: + title: Search by title + id: Search by id + Returns: + TYPE: Dictionary with movie data + """ + movie = {} + if kwargs is not None: + for key, value in iter(kwargs.items()): + if key == 'id': + movie = self._get_movie_by_id(value) + else: + movie = self._get_movie_by_args(key, value) + return movie + + def search(self, **kwargs): + """Return a list with the data of the movies. + + Args: + title: Search by title + director: Search by director + cast: Search by cast + from_year: Search from the year + to_year: Search until the year + Returns: + TYPE: Lis with movies data + """ + movies = [] + if kwargs is not None: + options = '' + for key, value in iter(kwargs.items()): + if key in FIELDS_TYPE: + options += 'stext=%s&stype[]=%s&' % (str(kwargs[key]), key) + if key == 'from_year': + options += 'fromyear=%s&' % value + if key == 'to_year': + options += 'toyear=%s&' % value + url = self.url + 'advsearch.php?' + options + page = requests.get(url) + soup = BeautifulSoup(page.text, "html.parser") + movies_cell = soup.find_all("div", {"class": 'movie-card'}) + for cell in movies_cell: + movie = { + 'title': self._get_title_by_search(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_filmaffinity(self, **kwargs): + """Return a list with the top filmaffinity movies. + + Args: + + from_year: Search from the year + to_year: Search until the year + Returns: + TYPE: Lis with movies data + """ + movies = [] + if kwargs is not None: + options = '' + for key, value in iter(kwargs.items()): + if key == 'from_year': + options += 'fromyear=%s&' % value + if key == 'to_year': + options += 'toyear=%s&' % value + if options: + url = self.url + 'topgen.php?' + options + else: + url = self.url + 'topgen.php' + page = requests.get(url) + soup = BeautifulSoup(page.text, "html.parser") + movies_cell = soup.find_all("div", {"class": 'movie-card'}) + for cell in movies_cell: + movie = { + 'title': self._get_title_by_search(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_premieres(self): + """Return a list with the top filmaffinity movies. + + Args: + + from_year: Search from the year + to_year: Search until the year + Returns: + TYPE: Lis with movies data + """ + movies = [] + url = self.url + 'topcat_new_th_es.html' + page = requests.get(url) + soup = BeautifulSoup(page.text, "html.parser") + movies_cell = soup.find_all("div", {"class": 'movie-card'}) + for cell in movies_cell: + movie = { + 'title': self._get_title_by_search(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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1c65988 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,35 @@ +setuptools==28.8.0 +aarpy==0.1 +appdirs==1.4.3 +astroid==1.5.2 +backports.functools-lru-cache==1.4 +backports.shutil-get-terminal-size==1.0.0 +beautifulsoup4==4.6.0 +bs4==0.0.1 +configparser==3.5.0 +coveralls==1.1 +decorator==4.0.11 +enum34==1.1.6 +ipython==5.3.0 +ipython-genutils==0.2.0 +isort==4.2.5 +lazy-object-proxy==1.3.1 +mccabe==0.6.1 +packaging==16.8 +pathlib2==2.2.1 +pep8==1.7.0 +pexpect==4.2.1 +pickleshare==0.7.4 +prompt-toolkit==1.0.14 +ptyprocess==0.5.1 +Pygments==2.2.0 +pylint==1.7.1 +pyparsing==2.2.0 +pytest==3.1.0 +requests==2.0.1 +scandir==1.5 +simplegeneric==0.8.1 +singledispatch==3.4.0.3 +traitlets==4.3.2 +wcwidth==0.1.7 +wrapt==1.10.10 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0a1c097 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[python_filmaffinity:pytest] +norecursedirs = env +addopts = --doctest-modules -v -s + +[bdist_wheel] +universal = 1 + +[pep8] +exclude = .tox,env,docs + +[aliases] +test=pytest + +[tool:pytest] +python_files = tests/*.py \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..905958e --- /dev/null +++ b/setup.py @@ -0,0 +1,51 @@ +""" +omdb +==== + +Python wrapper for OMDbAPI.com. + +Project: https://github.com/dgilland/omdb.py +""" + +import os +from setuptools import setup, find_packages + + +def read(fname): + return open(os.path.join(os.path.dirname(__file__), fname)).read() + + +meta = {} +exec(read('__meta__.py'), meta) + +setup( + name=meta['__title__'], + version=meta['__version__'], + url=meta['__url__'], + setup_requires=['pytest-runner'], + tests_require=['pytest'], + license=meta['__license__'], + author=meta['__author__'], + author_email=meta['__email__'], + description=meta['__summary__'], + # this must be the same as the name above + packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", + "tests", "*tests*"]), + 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.1', + keywords='filmaffinity movies films', + classifiers=[ + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4' + ] +) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29