import urllib2
import json
import pandas as pd

"""
Explanation: WEB_API Scrapper
End of explanation
"""


url = urllib2.urlopen('http://api.nytimes.com/svc/books/v3/lists/2015-10-01/hardcover-fiction.json?callback=books&sort-by=rank&sort-order=DESC&api-key=efb1f6ff386ce33c0b913d44bce40fd8%3A10%3A73015082')

"""
Explanation: I would like to get the Best Seller list for the Month of October 2015. First I signed up to the New York Times API, and afterwards received a key in seconds.
End of explanation
"""


data = json.load(url)

"""
Explanation: Above I've used the urllib module and its urlopen method to request the data using the NY Times Books API. What is returned is a json file, that must be loaded into python using the json module and load method.
End of explanation
"""


clean_data = {}

for item in data['results']['books']:
    clean_data[item['rank']] = [item['title'], item['author'], item['primary_isbn10'], item['primary_isbn13'], item['description']]

"""
Explanation: After viweing the information in the data variable which gives access to the json file. I've decided to create a dictionary to save the information in as we loop through the data json life.
End of explanation
"""


clean_data

best_seller = pd.DataFrame(clean_data.values(), columns = ['Title', 'Author', 'ISBN:10', 'ISBN:13', 'Description'], 
                          index = clean_data.keys())

"""
Explanation: After parsing through the data i chose to collect the book ranks, title, authors, and both 10 digit and 13 digit ISBN along with a description of the books.
End of explanation
"""


best_seller

"""
Explanation: What i am left with is a DataFrame from the  clean_data dictionary as the data and manual titled columns, indexed by the Ranking of the books.
End of explanation
"""


