<commit_before>#!/usr/bin/env python

import urllib
import json
import os


from flask import Flask
from flask import request
from flask import make_response

from flask import render_template
import sys
import logging

# Flask app should start in global layout
app = Flask(__name__)

app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)

@app.route('/webhook', methods=['POST'])
def webhook():
    req = request.get_json(silent=True, force=True)

    print("Request:")
    print(json.dumps(req, indent=4))

    res = processRequest(req)

    res = json.dumps(res, indent=4)
    # print(res)
    r = make_response(res)
    r.headers['Content-Type'] = 'application/json'
    return r


# def processRequest(req):
#     if req.get("result").get("action") != "yahooWeatherForecast":
#         return {}
#     baseurl = "https://query.yahooapis.com/v1/public/yql?"
#     yql_query = makeYqlQuery(req)
#     if yql_query is None:
#         return {}
#     yql_url = baseurl + urllib.urlencode({'q': yql_query}) + "&format=json"
#     result = urllib.urlopen(yql_url).read()
#     data = json.loads(result)
#     res = makeWebhookResult(data)
#     return res

def processRequest(req):
    if req.get("result").get("action") != "foursquareAPIsDemo":
        return {}
    result = req.get("result")
    parameters = result.get("parameters")
    city = parameters.get("geo-city")
    food_order = parameters.get("food_order")
    fun_activity = parameters.get("fun_activity")
    movie_activity = parameters.get("movie")
    given_address = parameters.get('area_bangalore')
    google_map_url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + given_address +"&key=<KEY>"
    map_result = urllib.url_map_open(google_map_url).read()
    map_data = json.loads(map_result)
    results = map_data.get('results')
    geometry = results[0].get('geometry').get('location')
    lat = geometry.get('lat')
    lng = geometry.get('lng')

    if fun_activity:
        query = fun_activity
    if food_order:
        query = food_order
    if movie_activity:
        query = movie_activity
    baseurl = "https://api.foursquare.com/v2/venues/search?"
    yql_url = baseurl + "client_id=FBR415TEGJMA13MWR0ZXS2RD0KO1PBVEEFKBNPC5Y1K23FHQ&client_secret=EIGPMK3AV4IALOK4KJWIKJH1AA40R1KVKP2L3VY5O0TD5KBL&v=20130815&near=" + city + "&query=" + query
    yql_url_map = baseurl + "client_id=FBR415TEGJMA13MWR0ZXS2RD0KO1PBVEEFKBNPC5Y1K23FHQ&client_secret=EIGPMK3AV4IALOK4KJWIKJH1AA40R1KVKP2L3VY5O0TD5KBL&v=20130815&ll="+lat+","+lng"&query=sushi&format=json"
    sys.stdout.write(yql_url)
    result = urllib.urlopen(yql_url).read()
    data = json.loads(result)
    res = makeWebhookResult(data)
    return res


# def makeYqlQuery(req):
#     result = req.get("result")
#     parameters = result.get("parameters")
#     city = parameters.get("geo-city")
#     if city is None:
#         return None<commit_msg>adding local areas<commit_after>#!/usr/bin/env python

import urllib
import json
import os


from flask import Flask
from flask import request
from flask import make_response

from flask import render_template
import sys
import logging

# Flask app should start in global layout
app = Flask(__name__)

app.logger.addHandler(logging.StreamHandler(sys.stdout))
app.logger.setLevel(logging.ERROR)

@app.route('/webhook', methods=['POST'])
def webhook():
    req = request.get_json(silent=True, force=True)

    print("Request:")
    print(json.dumps(req, indent=4))

    res = processRequest(req)

    res = json.dumps(res, indent=4)
    # print(res)
    r = make_response(res)
    r.headers['Content-Type'] = 'application/json'
    return r


# def processRequest(req):
#     if req.get("result").get("action") != "yahooWeatherForecast":
#         return {}
#     baseurl = "https://query.yahooapis.com/v1/public/yql?"
#     yql_query = makeYqlQuery(req)
#     if yql_query is None:
#         return {}
#     yql_url = baseurl + urllib.urlencode({'q': yql_query}) + "&format=json"
#     result = urllib.urlopen(yql_url).read()
#     data = json.loads(result)
#     res = makeWebhookResult(data)
#     return res

def processRequest(req):
    if req.get("result").get("action") != "foursquareAPIsDemo":
        return {}
    result = req.get("result")
    parameters = result.get("parameters")
    city = parameters.get("geo-city")
    food_order = parameters.get("food_order")
    fun_activity = parameters.get("fun_activity")
    movie_activity = parameters.get("movie")
    given_address = parameters.get('area_bangalore')
    google_map_url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + given_address +"&key=<KEY>2O10zU8TomUalu2mK_g"
    sys.stdout.write(google_map_url)
    map_result = urllib.url_map_open(google_map_url).read()
    map_data = json.loads(map_result)
    results = map_data.get('results')
    geometry = results[0].get('geometry').get('location')
    lat = geometry.get('lat')
    lng = geometry.get('lng')

    if fun_activity:
        query = fun_activity
    if food_order:
        query = food_order
    if movie_activity:
        query = movie_activity
    baseurl = "https://api.foursquare.com/v2/venues/search?"
    yql_url = baseurl + "client_id=FBR415TEGJMA13MWR0ZXS2RD0KO1PBVEEFKBNPC5Y1K23FHQ&client_secret=EIGPMK3AV4IALOK4KJWIKJH1AA40R1KVKP2L3VY5O0TD5KBL&v=20130815&near=" + city + "&query=" + query
    yql_url = baseurl + "client_id=FBR415TEGJMA13MWR0ZXS2RD0KO1PBVEEFKBNPC5Y1K23FHQ&client_secret=EIGPMK3AV4IALOK4KJWIKJH1AA40R1KVKP2L3VY5O0TD5KBL&v=20130815&ll="+lat+","+lng"&query=sushi&format=json"
    sys.stdout.write(yql_url)
    result = urllib.urlopen(yql_url).read()
    data = json.loads(result)
    res = makeWebhookResult(data)
    return res


# def makeYqlQuery(req):
#     result = req.get("result")
#     parameters = result.get("parameters")
#     city = parameters.get("geo-city")
#     if city is None:
#         return None
{'fraction_non_alphanumeric': 0.13468354430379748, 'fraction_numerical': 0.02481012658227848, 'mean_word_length': 4.082332761578044, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '147434', 'n_tokens_mistral': 2237, 'n_tokens_neox': 2146, 'n_words': 344}