import os
from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
import requests
import json
from hotels.zomat import Zomat
from hotels.fb import FB

@api_view(['GET','POST'])
def get_hotel_info(request):
    # get all Hotel Categories
    if request.method == 'GET':
        print (request.body)
        body_unicode = request.body.decode('utf-8')
        zomato_url="https://developers.zomato.com/api/v2.1/categories"
        headers={"Accept":"applicaiton/json",
        "user-key": "b0fcc8e574f96ad3e80be23d898aa861"}
        resp=requests.get(zomato_url,headers=headers)
        print (resp.content)
        jresp=json.loads(resp.text)
        print (jresp)
        return Response(jresp)
    if request.method == 'POST':
        print (request.body)
        body_unicode = request.body.decode('utf-8')
        body = json.loads(body_unicode)
        fb = FB(body)
        zom = Zomat()
        loc = str()
        entity_id = 0
        cuisine_id = 0
        entity_type = str()

        query_json = body['result']['parameters']
        if "NEW_USER_STARTED" in body['originalRequest']['data']['postback']['payload']:
            print("A new user")
            if fb.isFacebook():
                fb.independantTextMessage(fb.sender_id, "Hey there, Foodie !!! I'm JugheadBot, your friendly neighbourhood Restaurant finding Bot")
                fb.independantTextMessage(fb.sender_id, "You can ask me following questions:")
                fb.independantTextMessage(fb.sender_id, "\"Which are the best Restaurants in Kothrud, Pune\"")
                fb.independantTextMessage(fb.sender_id, "\"Which are the best Chinese Restaurants in Dadar, Mumbai\"")
                fb.independantTextMessage(fb.sender_id, "\"What is the review of Blue Nile in Camp Area, Pune\"")
                return Response("{}")

        if query_json['geo-city']:
            city = query_json['geo-city']
            loc = city
            print (city)
        if query_json['area']:
            area = query_json['area']
            print (area)
            loc = area + " " + loc
        entity_id, entity_type = zom.getLocation(str(loc))
        print ("entity_id = ",entity_id, ", entity_type = ", entity_type)

        messages = []
        restaurant_list = []

        if "Cuisines" in query_json:
            cuisine = str()
            cuisine = query_json['Cuisines']
            print (cuisine)
            cuisine_id = zom.getCuisineID(city, cuisine)
            print("cuisine_id = ", cuisine_id)
            if int(cuisine_id) == 0:
                messages = fb.textMessage(messages, "Could not find Restaurants for your specific Cuisine. Could you maybe re-check the spelling and try again?")
            else:
                restaurant_list = zom.getBestRestaurants(entity_id, entity_type, cuisine_id)
                # Update FB Card message with Restaurant list
                messages = fb.cardMessage(messages, restaurant_list)
        elif "res-name" in query_json:
            print ("This is a query for a Review")
            res_name = query_json['res-name']
            print (res_name)
            restaurant_review = zom.getReviews(res_name, entity_id, entity_type)
            messages = fb.cardMessage(messages, restaurant_review)
        else:
            # Just get the Top 5 Restaurants in the location
            restaurant_list = zom.getBestRestaurants(entity_id, entity_type)
            messages = fb.cardMessage(messages, restaurant_list)

        response = {
            "messages" : messages
        }
        print(response)
        return Response(response)

@@ -1147,16 +1147,64 @@
      if 
+body%5B'originalRequest'%5D%5B'data'%5D%5B'postback'%5D and 
 %22NEW_USE

Check for Postback message