Ejemplo n.º 1
0
def get_recommendations(url):
    recommend_api = 'http://chat-01.heron.safaribooks.com/chat/by-popularity?start=1&topic='
    recommended_url = 'http://www.safariflow.com/library/view/_/{fpid}/{chunk}'
    #Get the tags for the given URL
    success, result = Recommender.get_url_page_contents(url)
    if success:
        tokenizedTags = Recommender.getTags(result)
        #Get the matched topic from those keywords
        matchedTopic = Recommender.matchTopic(tokenizedTags)
        #Form the recommendation url
        apiurl = recommend_api + matchedTopic
        #fetch the safari recommendation url
        result = Recommender.fetchSafariRecommendation(apiurl)
        return True, recommended_url.format(**result)
    else:
        return False, result