<commit_before>#!/usr/bin/python
# encoding: utf-8

# gets the dump1090 JSON, assumes its on localhost
from __future__ import print_function
import requests
import re
import geojson
from sys import stderr
from shapely.geometry import Point, shape

class Flyover:
  flight_num_re = re.compile("^[A-Z]{2,3}\d+$", re.IGNORECASE)

  @classmethod
  def get_nearest_airplane(self, options):
    if options.location:
      lat, lon = options.location.split(",")
      location = {"lon": float(lon),"lat": float(lat)}
    else:
      location =      requests.get("http://%s/dump1090/data/receiver.json" % options.host).json()
      try: 
        location["lat"]
      except KeyError, e:
        raise(KeyError("Your Dump1090 installation doesn't disclose its location. Specify your location with the --location option."))
        
    aircraft_resp = requests.get("http://%s/dump1090/data/aircraft.json" % options.host).json()
    flights = aircraft_resp["aircraft"]
    flights = [f for f in flights if "flight" in f and self.flight_num_re.match(f["flight"].strip()) and f["seen"] < 60] 
    def distance(f):
      return ((f.get("lat", 0) - location["lat"]) ** 2 + (f.get("lon", 0) - location["lon"]) ** 2) ** 0.5

    def within_area(flight, area_geojson_location):
      if not area_geojson_location:
        return True
      try:
        with open(area_geojson_location, 'r') as geo:
          bounds = geojson.loads(geo.read())["geometry"]
          flight_loc = Point(f.get("lon", 0), f.get("lat", 0))
          return shape(bounds).contains(flight_loc)<commit_msg>expand geojson location in a 'shell like fashion'<commit_after>#!/usr/bin/python
# encoding: utf-8

# gets the dump1090 JSON, assumes its on localhost
from __future__ import print_function
import requests
import re
import geojson
from sys import stderr
from shapely.geometry import Point, shape
from os import path

class Flyover:
  flight_num_re = re.compile("^[A-Z]{2,3}\d+$", re.IGNORECASE)

  @classmethod
  def get_nearest_airplane(self, options):
    if options.location:
      lat, lon = options.location.split(",")
      location = {"lon": float(lon),"lat": float(lat)}
    else:
      location =      requests.get("http://%s/dump1090/data/receiver.json" % options.host).json()
      try: 
        location["lat"]
      except KeyError, e:
        raise(KeyError("Your Dump1090 installation doesn't disclose its location. Specify your location with the --location option."))
        
    aircraft_resp = requests.get("http://%s/dump1090/data/aircraft.json" % options.host).json()
    flights = aircraft_resp["aircraft"]
    flights = [f for f in flights if "flight" in f and self.flight_num_re.match(f["flight"].strip()) and f["seen"] < 60] 
    def distance(f):
      return ((f.get("lat", 0) - location["lat"]) ** 2 + (f.get("lon", 0) - location["lon"]) ** 2) ** 0.5

    def within_area(flight, area_geojson_location):
      if not area_geojson_location:
        return True
      try:
        with open(path.expanduser(area_geojson_location), 'r') as geo:
          bounds = geojson.loads(geo.read())["geometry"]
          flight_loc = Point(f.get("lon", 0), f.get("lat", 0))
          return shape(bounds).contains(flight_loc)
{'fraction_non_alphanumeric': 0.14508580343213728, 'fraction_numerical': 0.018096723868954757, 'mean_word_length': 3.4220689655172416, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4413821', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1013, 'n_words': 262}