Example #1
0
from miner.themoviedb import get_api_response
from math import log10
from numpy import logspace

# '/tv/popular' or '/movie/popular'
resource = '/tv/popular'
total_pages = get_api_response(resource).get('total_pages')

# Make a number of logaritmically spaced page numbers
pages = logspace(0, log10(total_pages), num=40)

# Make page numbers integer and remove duplicates.
for page in sorted(list(set(map(int, map(round, pages))))):
    response = get_api_response(resource, {'page': page})
    s = 'Page {:>4} - Rank {:>6}: '.format(page, 1+20*(page-1))
    # {name} for tv, {title} for movies
    s += 'id:{id:>7}, pop:{popularity:>11.6f}, title: {name}'.format(
            **response['results'][0])
    print(s)


# # On feb 21, 2016, 14:50:
# 
# Page    1 - Rank      1: id: 293660, pop: 100.588117, title: Deadpool
# Page    2 - Rank     21: id: 337339, pop:  13.263573, title: Fast 8
# Page    3 - Rank     41: id:  99861, pop:  10.428954, title: Avengers: Age of Ultron
# Page    4 - Rank     61: id: 254128, pop:   8.815580, title: San Andreas
# Page    5 - Rank     81: id:    272, pop:   7.448537, title: Batman Begins
# Page    6 - Rank    101: id: 109445, pop:   6.736811, title: Frozen
# Page    7 - Rank    121: id: 228161, pop:   6.211710, title: Home
# Page    8 - Rank    141: id:     98, pop:   5.759105, title: Gladiator
Example #2
0
def test_get_api_response():
    config = get_api_response('/configuration')
    assert config['images']['base_url'] == 'http://image.tmdb.org/t/p/'
    assert config['images']['secure_base_url'] == 'https://image.tmdb.org/t/p/'
    r = get_api_response('/movie/popular', {'page': 2})
    assert r['page'] == 2