def main():
    db = utils.connect_db('Two_Pick_Too_Drunk')
    beer_collection = db['beer']

    ObannonsBeerList = OBD.keys()
    
    print 'Sorting Obannon\'s reviews'
    reviews = utils.read_beers()
    obannonsReviews = list()
    obannonsDict = dict()
    json = open('Reviews/ObannonsData.json','w')
    for review in reviews:
        if review['BeerId'] in ObannonsBeerList:
            obannonsReviews.append(review)
            s = ujson.dumps(review)
            json.write(s+'\n')
    json.close()
    reviewersorter = review_sorter('obannons_reviews')
    reviewersorter.sort_reviews(obannonsReviews)

    for review in obannonsReviews:
        if review['BeerId'] in obannonsDict:
            obannonsDict[review['BeerId']].append(review['Reviewer'])
        else:
            obannonsDict[review['BeerId']] = [review['Reviewer']]

    print 'Reveiews per Obannons Beers'
    for beer in obannonsDict:
        Beer = beer_collection.find_one({"BeerId":beer})
        print 'Beer: '+Beer['Brewery']+ ' '+ Beer['Name'] + '\nNumber of reviews: '+str(len(obannonsDict[beer]))+'\n'
def main():
    db = utils.connect_db('Two_Pick_Too_Drunk')
    beer_collection = db['beer']
    beer_collection.remove()
    
    beer_rating = BeerAverage()

    print 'Loading Beers'
    beers = utils.read_beers()
    brewery = []
    beersCount = 0
    for beer in beers:
        beersCount +=1
        if beer['Brewery'] not in brewery:
            brewery.append(beer['Brewery'])
        
        if beer['BeerId'] in beer_rating:
            doc = {'Brewery'   : beer['Brewery'],
                   'BeerId'    : beer['BeerId'],
                   'Name'      : beer['Name'],
                   'BreweryId' : beer['BreweryId'],
                   'AverageRating': beer_rating[beer['BeerId']]
                  }
        else:
            doc = {'Brewery'   : beer['Brewery'],
                   'BeerId'    : beer['BeerId'],
                   'Name'      : beer['Name'],
                   'BreweryId' : beer['BreweryId']
                  }

        beer_collection.insert(doc)
    print str(beersCount) + ' Beers over ' + str(len(brewery)) + ' Brewerys'
def main():
    db = utils.connect_db('Two_Pick_Too_Drunk')
    beer_collection = db['beer']
    beer_collection.remove()
    
    beer_rating = BeerAverage()

    print 'Loading Beers'
    beers = utils.read_beers()
    brewery = []
    beersCount = 0
    for beer in beers:
        beersCount +=1
        if beer['Brewery'] not in brewery:
            brewery.append(beer['Brewery'])
        
        if beer['BeerId'] in beer_rating:
            doc = {'Brewery'   : beer['Brewery'],
                   'BeerId'    : beer['BeerId'],
                   'Name'      : beer['Name'],
                   'BreweryId' : beer['BreweryId'],
                   'AverageRating': beer_rating[beer['BeerId']]
                  }
        else:
            doc = {'Brewery'   : beer['Brewery'],
                   'BeerId'    : beer['BeerId'],
                   'Name'      : beer['Name'],
                   'BreweryId' : beer['BreweryId']
                  }

        beer_collection.insert(doc)
    print str(beersCount) + ' Beers over ' + str(len(brewery)) + ' Brewerys'
    search = Search()
    beers = beer_collection.find()
    search.index_beers(beers)
    print 'inputing into DB'
    for beer in search.beers:
        beerData=  search.beers[beer]
        beer_collection.update({"BeerId":beerData['BeerId']},{"$set":{"tokens":beerData["tokens"],"vect":beerData["vect"]}})
    index = {}
    for x in search.index:
        index[x] = list(search.index[x])
    db['search'].remove({"SearchIndex":"Beer"})
    db['search'].insert({"SearchIndex":"Beer","Index":index,"termIdf":search.term_idf})    
def main():
    reviews = utils.read_beers()
    sorter = review_sorter()
    sorter.sort_reviews(reviews)