예제 #1
0
def do_request(url, oauth, carcel, payload, geocode):
    if payload != None:
        r = requests.get(url=url, auth=oauth, params=payload)
        data = r.json()
    else:
        r = requests.get(url=url, auth=oauth)
        data = r.json()
    try:
        next_results = data['search_metadata']['next_results']
        print next_results
    except:
        print "There are not next_results"
        next_results = "None"
    for status in data['statuses']:
        obj = {}
        obj['carcel'] = carcel
        status_id = status['id']
        obj['status_id'] = status_id

        text = status['text']
        obj['text'] = text

        screen_name = status['user']['screen_name']
        obj['screen_name'] = screen_name

        profile_img_url = status['user']['profile_image_url_https']
        download_profile_image(profile_img_url, screen_name)

        utc_offset = status['user']['utc_offset']
        obj['utc_offset'] = utc_offset

        user_id = status['user']['id']
        obj['user_id'] = user_id

        created_at = status['created_at']
        obj['created_at'] = created_at

        if 'geo' in status and status['geo'] != None:
            latitude = status['geo']['coordinates'][0]
            longitude = status['geo']['coordinates'][1]
            obj['latitude'] = latitude
            obj['longitude'] = longitude
            obj['retuited'] = "no"
            obj['in_jail'] = "no"

            if calc_distance(latitude, longitude, float(geocode.split(",")[0]),
                             float(geocode.split(",")[1])) < 1.1:
                print obj['status_id'], calc_distance(
                    latitude, longitude, float(geocode.split(",")[0]),
                    float(geocode.split(",")[1]))
                insert_data(obj)

    return next_results
def do_request(url, oauth, carcel, payload, geocode):
    if payload != None:
        r = requests.get(url=url, auth=oauth, params=payload)
        data = r.json()
    else:
        r = requests.get(url=url, auth=oauth)
        data = r.json()
    try:
        next_results = data['search_metadata']['next_results']
        print next_results
    except:
        print "There are not next_results"
        next_results = "None"
    for status in data['statuses']:
        obj = {}
        obj['carcel'] = carcel
        status_id = status['id']
        obj['status_id'] = status_id

        text = status['text']
        obj['text'] = text

        screen_name = status['user']['screen_name']
        obj['screen_name'] = screen_name

        profile_img_url = status['user']['profile_image_url_https']
        download_profile_image(profile_img_url, screen_name)

        utc_offset = status['user']['utc_offset']
        obj['utc_offset'] = utc_offset

        user_id = status['user']['id']
        obj['user_id'] = user_id

        created_at = status['created_at']
        obj['created_at'] = created_at
        
        if 'geo' in status and status['geo'] != None:
            latitude = status['geo']['coordinates'][0]
            longitude = status['geo']['coordinates'][1]
            obj['latitude'] = latitude
            obj['longitude'] = longitude
            obj['retuited'] = "no"

            if calc_distance(latitude, longitude, float(geocode.split(",")[0]), float(geocode.split(",")[1])) < 1.1:
                print obj['status_id'], calc_distance(latitude, longitude, float(geocode.split(",")[0]), float(geocode.split(",")[1]))
                insert_data(obj)

    return next_results
예제 #3
0
def delete(penal, coord):
    db = dataset.connect("sqlite:///tuits.db")
    table = db['tuits']
    res = table.find(carcel=penal)

    to_delete = []
    for i in res:
        dist = calc_distance(coord[0], coord[1], i['latitude'], i['longitude'])
        if dist > 1.1:
            to_delete.append(i['id'])

    for my_id in to_delete:
        print "Removing %i" % my_id
        table.delete(id=my_id)
def delete(penal, coord):
    db = dataset.connect("sqlite:///tuits.db")
    table = db['tuits']
    res = table.find(carcel=penal)

    to_delete = []
    for i in res:
        dist = calc_distance(coord[0],coord[1],i['latitude'],i['longitude'])
        if dist > 1.1:
            to_delete.append(i['id'])

    for my_id in to_delete:
        print "Removing %i" % my_id
        table.delete(id=my_id)
예제 #5
0
def distance(draw):
    d = l.calc_distance(s.message[2], s.latitude, s.longitude)

    if d != 0:
        i = 0
        #d = str(d) + 'KM'
        d = str(d)
        #if '.0' in d:
        #    d = d[:-2]

        for c in d:
            legacy.text(draw, (i, 0),
                        chr(s.letter[c]),
                        fill='white',
                        font=s.SMALL_BITMAP_FONT)
            i += 4
예제 #6
0
def distance(draw):
    d = l.calc_distance(s.message[1], s.latitude, s.longitude)
    j = 18

    if d is False:
        d = 'NO LOC'
    else:
        d = str(d)

    i = 128 - len(d) * 4

    for c in d:
        legacy.text(draw, (i, j),
                    chr(s.letter[c]),
                    fill=get_color('screen', 'foreground'),
                    font=s.SMALL_BITMAP_FONT)
        i += 4
예제 #7
0
def delete(penal, coord):
    import config
    import os

    dbfile = os.path.join(config.local_folder, "tuits.db")
    db = dataset.connect("sqlite:///" + dbfile)
    table = db['tuits']
    res = table.find(carcel=penal)

    to_delete = []
    for i in res:
        dist = calc_distance(coord[0],coord[1],i['latitude'],i['longitude'])
        if dist > 1.1:
            to_delete.append(i['id'])

    for my_id in to_delete:
        print "Removing %i" % my_id
        table.delete(id=my_id)
예제 #8
0
def delete(penal, coord):
    import config
    import os

    dbfile = os.path.join(config.local_folder, "tuits.db")
    db = dataset.connect("sqlite:///" + dbfile)
    table = db["tuits"]
    res = table.find(carcel=penal)

    to_delete = []
    for i in res:
        dist = calc_distance(coord[0], coord[1], i["latitude"], i["longitude"])
        if dist > 1.1:
            to_delete.append(i["id"])

    for my_id in to_delete:
        print "Removing %i" % my_id
        table.delete(id=my_id)
예제 #9
0
with open(os.path.join(working_dir, 'resources/config.json')) as fp:
    config = json.load(fp)

airports_db = pd.read_csv(os.path.join(working_dir, 'resources/airports.csv'))
aircraft_db = pd.read_csv(os.path.join(working_dir, 'resources/aircraft.csv'))
start_lat = round((float)(airports_db.lat[airports_db.IATA == config['IATA']]),
                  5)
start_lon = round((float)(airports_db.lon[airports_db.IATA == config['IATA']]),
                  5)

departures = lib.retrieveFlights(config)
if len(departures) > 0:
    departures = departures.merge(airports_db, on='IATA', how='left')

    departures['km'] = departures.apply(
        lambda row: lib.calc_distance(start_lat, start_lon, row.lat, row.lon),
        axis=1)
    departures['type'] = departures.apply(lib.get_flight_type, axis=1)

    if os.environ["FLIGHTAWARE_KEY"]:
        credentials = {
            'User': '******',
            'Key': os.environ["FLIGHTAWARE_KEY"]
        }
    else:
        credentials = None

    departures[['code', 'name',
                'f']] = departures.apply(lib.get_aircraft_inf,
                                         args=[aircraft_db, credentials],
                                         axis=1,