<commit_before>from base import *
import urllib2, json

# categorized tags
TYPES = [
  ["restaurant", "food", "bar", "night_club", "lodging", "meal_delivery", "meal_takeaway", "cafe", \
  "grocery_or_supermarket", "bakery"], 
  ["airport", "taxi_stand", "train_station", "taxi", "plane", "train", "transport", "subway_station", "bus_station"],
  ["store", "shoe_store", "shopping_mall", "mall", "clothing_store", "convenience_store", \
  "hardware_store", "home_goods_store", "bicycle_store", "book_store", "department_store", "electronics_store", \
  "furniture_store", "jewelry_store", "liquor_store", "pet_store"],
  ["church", "religion", "hindu_temple", "synagogue", "place_of_worship", "mosque"],
  ["police", "fire_station", "emergency", "hospital", "doctor", "dentist", "physiotherapist", "pharmacy", "veterinary_care"],
  ["car_dealer", "car_rental", "car_repair", "car_wash"],
  ["health", "gym"],
  ["local_government_office", "embassy", "city_hall", "courthouse"],
  ["school", "university"],
  ["accounting", "finance", "bank", "atm"],
  ["general_contractor", "plumber", "electrician", "locksmith"],
  ["art", "museum", "painter", "florist"],
  ["amusement_park"],
  ["aquarium"],
  ["art_gallery"],
  ["beauty_salon"],
  ["bowling_alley"],
  ["campground"],
  ["casino"],
  ["cemetery"],
  ["funeral_home"],
  ["gas_station"],
  ["hair_care"],
  ["insurance_agency"],
  ["laundry"],
  ["lawyer"],
  ["library"],
  ["movie_rental", "movie_theater"],
  ["moving_company"],
  ["park", "rv_park"],
  ["parking"],
  ["post_office"],
  ["real_estate_agency"],
  ["roofing_contractor"],
  ["spa"],
  ["stadium"],
  ["storage"],
  ["travel_agency"],
  ["zoo"]
]

# main class
class pigeonParser(parser):

  def __init__(self, *args, **kwargs):
    super(pigeonParser, self).__init__(*args, **kwargs)

  def validate(self): 
    querystr = ' '.join(self.query)
    for cat in TYPES:
      for item in cat:
        if item.replace('_', ' ') in querystr:
          return cat

    return False

  # parse user's query
  def parse(self, parent):

    # get api key
    if self.info.has_key("key"):
      key = self.info["key"]
    else:
      raise InvalidKeyException, "Please enter a valid Google Places API key in Pigeon's info.json"

    # get our location
    qry = urllib2.urlopen("http://freegeoip.net/json/108.12.40.9")
    l = json.loads( qry.read() )
    pos_lat, pos_long = l["latitude"], l["longitude"]

    # test query
    qry = urllib2.urlopen(
      "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=%s&location=%s,%s&sensor=true&radius=5000" % 
      ( key, pos_lat, pos_long ))

    data = json.loads( qry.read() )

    # now, get all the places from the data
    places = []
    for p in data["results"]:
      place = {}
      # filter out whats not open
      if (p.has_key("opening_hours") and p["opening_hours"]["open_now"]) or not p.has_key("opening_hours"):
        place["name"] = p["name"]
        place["types"] = p["types"]
        places.append(place)


    # filter places depending on what user said
    tags = []
    items = []
    querystr = ' '.join(self.query)
    for cat in TYPES:
      for item in cat:
        # print item<commit_msg>replaced ip<commit_after>from base import *
import urllib2, json

# categorized tags
TYPES = [
  ["restaurant", "food", "bar", "night_club", "lodging", "meal_delivery", "meal_takeaway", "cafe", \
  "grocery_or_supermarket", "bakery"], 
  ["airport", "taxi_stand", "train_station", "taxi", "plane", "train", "transport", "subway_station", "bus_station"],
  ["store", "shoe_store", "shopping_mall", "mall", "clothing_store", "convenience_store", \
  "hardware_store", "home_goods_store", "bicycle_store", "book_store", "department_store", "electronics_store", \
  "furniture_store", "jewelry_store", "liquor_store", "pet_store"],
  ["church", "religion", "hindu_temple", "synagogue", "place_of_worship", "mosque"],
  ["police", "fire_station", "emergency", "hospital", "doctor", "dentist", "physiotherapist", "pharmacy", "veterinary_care"],
  ["car_dealer", "car_rental", "car_repair", "car_wash"],
  ["health", "gym"],
  ["local_government_office", "embassy", "city_hall", "courthouse"],
  ["school", "university"],
  ["accounting", "finance", "bank", "atm"],
  ["general_contractor", "plumber", "electrician", "locksmith"],
  ["art", "museum", "painter", "florist"],
  ["amusement_park"],
  ["aquarium"],
  ["art_gallery"],
  ["beauty_salon"],
  ["bowling_alley"],
  ["campground"],
  ["casino"],
  ["cemetery"],
  ["funeral_home"],
  ["gas_station"],
  ["hair_care"],
  ["insurance_agency"],
  ["laundry"],
  ["lawyer"],
  ["library"],
  ["movie_rental", "movie_theater"],
  ["moving_company"],
  ["park", "rv_park"],
  ["parking"],
  ["post_office"],
  ["real_estate_agency"],
  ["roofing_contractor"],
  ["spa"],
  ["stadium"],
  ["storage"],
  ["travel_agency"],
  ["zoo"]
]

# main class
class pigeonParser(parser):

  def __init__(self, *args, **kwargs):
    super(pigeonParser, self).__init__(*args, **kwargs)

  def validate(self): 
    querystr = ' '.join(self.query)
    for cat in TYPES:
      for item in cat:
        if item.replace('_', ' ') in querystr:
          return cat

    return False

  # parse user's query
  def parse(self, parent):

    # get api key
    if self.info.has_key("key"):
      key = self.info["key"]
    else:
      raise InvalidKeyException, "Please enter a valid Google Places API key in Pigeon's info.json"

    # get our location
    qry = urllib2.urlopen("http://freegeoip.net/json")
    l = json.loads( qry.read() )
    pos_lat, pos_long = l["latitude"], l["longitude"]

    # test query
    qry = urllib2.urlopen(
      "https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=%s&location=%s,%s&sensor=true&radius=5000" % 
      ( key, pos_lat, pos_long ))

    data = json.loads( qry.read() )

    # now, get all the places from the data
    places = []
    for p in data["results"]:
      place = {}
      # filter out whats not open
      if (p.has_key("opening_hours") and p["opening_hours"]["open_now"]) or not p.has_key("opening_hours"):
        place["name"] = p["name"]
        place["types"] = p["types"]
        places.append(place)


    # filter places depending on what user said
    tags = []
    items = []
    querystr = ' '.join(self.query)
    for cat in TYPES:
      for item in cat:
        # print item
{'fraction_non_alphanumeric': 0.19240426867545513, 'fraction_numerical': 0.003452605147520402, 'mean_word_length': 4.090255591054313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '323289', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2260, 'n_words': 490}