def api_summary(category): models = AnalyzeSentiments.retrieve_all() list_of_polarities = [] list_of_ratings = {} pos_revs = 0 neg_revs = 0 neut_revs = 0 for model in models: if model.category == category: data = model.senti_polarity list_of_polarities.append(data) if data == "Positive": pos_revs += 1 elif data == "Negative": neg_revs += 1 elif data == "Neutral": neut_revs += 1 list_of_ratings.update({"Positive_count": pos_revs}) list_of_ratings.update({"Negative_count": neg_revs}) list_of_ratings.update({"Neutral_count": neut_revs}) list_of_ratings.update({"Total_count": len(list_of_polarities)}) list_of_ratings.update( {"Positive_rating": float(pos_revs) / len(list_of_polarities)}) list_of_ratings.update( {"Negative_rating": float(neg_revs) / len(list_of_polarities)}) list_of_ratings.update( {"Neutral_rating": float(neut_revs) / len(list_of_polarities)}) return create_json_response(list_of_ratings)
def get_all(): try: req_args = request.args properties = { key: value for key, value in req_args.iteritems() if key in AcquisitionModel._properties } properties['is_deleted'] = properties.get('is_deleted', False) query = AcquisitionModel.find_all_by_properties(**properties) page = req_args.get('page', None) size = req_args.get('size', 20 if page else None) sort = AcquisitionModel._properties[req_args.get('sort', 'created')] order = req_args.get('order', 'desc') query = query.order(sort if order == 'asc' else -sort if order == 'desc' else None) return create_json_response({ 'data': (query.fetch(size, offset=((page - 1) * size)) if page else query.fetch(size) if size else query.fetch()), 'total_count': query.count() }) except Exception as error: handle_error(error)
def api_search(): """ dynamic creation of api endpoint for search """ query_string = request.args.get('query', None) cursor = request.args.get('cursor', None) q = search_index(model, paginate_limit=paginate_limit, query_string=query_string, cursor=cursor, transformer=transformer) return create_json_response(q)
def api_retrieve(category): models = AnalyzeSentiments.retrieve_all() list_of_reviews = [] for model in models: if model.category == category: data = {"category": model.category, "content": model.review} list_of_reviews.append(data) return create_json_response(list_of_reviews)
def get(url_safe): try: entity = ndb.Key(urlsafe=url_safe).get() if entity is None or entity.is_deleted: raise ResourceNotFoundException( "No entity with url-safe '{}' exist.".format(url_safe)) return create_json_response(entity) except Exception as error: handle_error(error)
def api_create(): _json = request.get_json() email = _json.get('email') gb = GuestBookModel.create(email) """ sample of parent to child entity relationship where guestbook is parent and addressbook is child """ AddressModel.add(gb.key, 'test1') AddressModel.add(gb.key, 'test2') AddressModel.add(gb.key, 'test3') return create_json_response(gb)
def create(): try: req_body = request.get_json() {"name": "Syd" "Last_na"} {publishers} properties = { key: value for key, value in req_body.iteritems() if key in AcquisitionModel._properties } return create_json_response(AcquisitionModel(**properties).put().get()) except Exception as error: handle_error(error)
def api_evaluation(category): models = AnalyzeSentiments.retrieve_all() list_of_data = [] logging.info(models) for model in models: if model.category == category: data = { "category": model.category, "content": model.review, "polarity": model.senti_polarity, "score": model.senti_score, "magnitude": model.senti_magnitude } list_of_data.append(data) return create_json_response(list_of_data)
def api_me(): logging.info(session.get('user_info')) return create_json_response(session.get('user_info'))
def api_calendar(): email = "*****@*****.**" calendar_events = CalendarService.get_events(email) return create_json_response(calendar_events)
def api_storage(content, filename): response = {'path': CloudStorageService.upload(content, filename)} return create_json_response(response)
def api_addressbook_get(guestbook_key): ab = AddressModel.get_address_by_key(guestbook_key) return create_json_response(ab)
def api_list(): return create_json_response(GuestBookModel.get_all())
def api_ratings(): category1 = "Wonder Woman" category2 = "Deadpool" category3 = "Doctor Strange" models = AnalyzeSentiments.retrieve_all() list_of_polarities = [] list_of_polarities2 = [] list_of_polarities3 = [] list_of_all = {} list_of_ratings = {} list_of_ratings2 = {} list_of_ratings3 = {} pos_revs = 0 neg_revs = 0 neut_revs = 0 pos_revs2 = 0 neg_revs2 = 0 neut_revs2 = 0 pos_revs3 = 0 neg_revs3 = 0 neut_revs3 = 0 for model in models: if model.category == category1: data = model.senti_polarity list_of_polarities.append(data) if data == "Positive": pos_revs += 1 elif data == "Negative": neg_revs += 1 elif data == "Neutral": neut_revs += 1 elif model.category == category2: data = model.senti_polarity list_of_polarities2.append(data) if data == "Positive": pos_revs2 += 1 elif data == "Negative": neg_revs2 += 1 elif data == "Neutral": neut_revs2 += 1 elif model.category == category3: data = model.senti_polarity list_of_polarities3.append(data) if data == "Positive": pos_revs3 += 1 elif data == "Negative": neg_revs3 += 1 elif data == "Neutral": neut_revs3 += 1 # list_of_ratings.update({"Positive_count": pos_revs}) # list_of_ratings.update({"Negative_count": neg_revs}) # list_of_ratings.update({"Neutral_count": neut_revs}) # list_of_ratings.update({"Total_count": len(list_of_polarities)}) list_of_ratings.update( {"Positive_rating": float(pos_revs) / len(list_of_polarities)}) list_of_ratings.update( {"Negative_rating": float(neg_revs) / len(list_of_polarities)}) list_of_ratings.update( {"Neutral_rating": float(neut_revs) / len(list_of_polarities)}) # list_of_ratings2.update({"Positive_count": pos_revs2}) # list_of_ratings2.update({"Negative_count": neg_revs2}) # list_of_ratings2.update({"Neutral_count": neut_revs2}) # list_of_ratings2.update({"Total_count": len(list_of_polarities2)}) list_of_ratings2.update( {"Positive_rating": float(pos_revs2) / len(list_of_polarities2)}) list_of_ratings2.update( {"Negative_rating": float(neg_revs2) / len(list_of_polarities2)}) list_of_ratings2.update( {"Neutral_rating": float(neut_revs2) / len(list_of_polarities2)}) # list_of_ratings3.update({"Positive_count": pos_revs3}) # list_of_ratings3.update({"Negative_count": neg_revs3}) # list_of_ratings3.update({"Neutral_count": neut_revs3}) # list_of_ratings3.update({"Total_count": len(list_of_polarities3)}) list_of_ratings3.update( {"Positive_rating": float(pos_revs3) / len(list_of_polarities3)}) list_of_ratings3.update( {"Negative_rating": float(neg_revs3) / len(list_of_polarities3)}) list_of_ratings3.update( {"Neutral_rating": float(neut_revs3) / len(list_of_polarities3)}) list_of_all.update({"Movie1": list_of_ratings}) list_of_all.update({"Movie2": list_of_ratings2}) list_of_all.update({"Movie3": list_of_ratings3}) return create_json_response(list_of_all)