def all_restaurants():
    id_list = np.unique(reviews_df.business_id)
    data = []
    for _id in id_list:
        _dict = {}
        _dict['id'] = _id
        _dict['name'] = np.unique(reviews_df[reviews_df.business_id == _id].name)[0]
        print _id
        reviews = get_reviews(_id)
        try:
            cat_score = get_business_score(reviews,_id)
            _dict['cat_score'] = cat_score
            data.append(_dict)
        except:
            pass
    return render_template("all_restaurants.html",
                            title = "Yelp Review Categorization",
                            data = data)
def index():
    #bus_id = "vcNAWiLM4dR7D2nwwJ7nCA"
    #bus_id = "mVHrayjG3uZ_RLHkLj-AMg"
    #bus_id = "1qCuOcks5HRv67OHovAVpg"
    bus_id =  "wJr6kSA5dchdgOdwH6dZ2w"
    res = get_reviews(bus_id)
    try:
        cat_score  = get_business_score(res,bus_id)
        name = np.unique(reviews_df[reviews_df.business_id == bus_id].name)[0]
        print res
        return render_template("index.html",
                               title = "Yelp Review Categorization",
                               cat_score = cat_score,
                               res = res,
                               name = name)
    except Exception as e:
        print e
        print "nan",res
        return render_template("index.html",
        title = "Yelp Review Categorization",
        cat_score = {},
        res = [],
        name = " ")
import numpy as np
import pandas as pd
from JsonToDF import get_data
from review import reviews_df
from review.review_score import get_reviews
from business import get_business_score
import pickle

count = 1000
df = get_data(count)
print df.shape
id_list = np.unique(reviews_df.business_id)
data = []
for _id in id_list:
    _dict = {}
    _dict['id'] = _id
    _dict['name'] = np.unique(reviews_df[reviews_df.business_id == _id].name)[0]
    print _id
    reviews = get_reviews(_id)
    try:
        cat_score = get_business_score(reviews,_id)
        _dict['cat_score'] = cat_score
        data.append(_dict)
    except:
        pass
pickle.dump(data,open('data.p','w'))