[Tutor] Python OO

Juan C. juan0christian at gmail.com
Sun Mar 29 21:16:40 CEST 2015


Ok, applying what you guys said I have:

- folder: pycinema
- package: pycinema
- - core.py
- - mdb.py
- __main__.py

Current code on core.py:

# -*- coding: utf-8 -*-

from pycinema.mdb import MovieDB

API = MovieDB('API KEY GOES HERE')

class Actor:
def __init__(self, actor_id):
api = API.get_actor(actor_id)
self.name = api['name']
self.biography = api['biography']
self.actorid = api['id']

class Movie:
def __init__(self):
pass

class Series:
def __init__(self):
pass


Current code on mdb.py:

# -*- coding: utf-8 -*-

import requests

class MovieDB:
def __init__(self, api_key):
self.api_key = api_key

def get_actor(self, actor_id):
response = requests.get('http://api.themoviedb.org/3/person/' +
str(actor_id) + '?api_key=' + str(self.api_key)).json()
return {'name': response['name'], 'id': actor_id, 'biography':
response['biography']}


I think the get_actor return is a bit bad. What would be the best way to
return the data?

Should I use classes inside the MovieDB class (Actor, Movie, Series) and
inside those classes have different methods to get each data, like name,
birthday, bio, etc separately?

Only 1 call to the API gives all this data, example (
http://private-anon-37abaab74-themoviedb.apiary-mock.com/3/person/678). If
I have different methods to get each data separately, I would be calling
this same URL many times, when the best approach would be only 1.

I won't need to get the ID from the API, as the user must provide the ID
when instantiating the Actor.

If you can't read the source code, try here: http://pastebin.com/1DWjxQwH


More information about the Tutor mailing list