Exemplo n.º 1
0
 def run(self):
     gimbal = Gimbal(auth_key=config.GIMBAL_API_KEY)
     with open('data/dostuff_venues_021816.tsv', 'rb') as tsvfile:
         venues = csv.reader(tsvfile, delimiter='\t', quotechar='|')
         next(venues)
         for v in venues:
             address = "{}, {}".format(v[5], v[3])
             name = v[1]
             attributes={
                 'address':v[5],
                 'city':v[3]
             }
             logging.info(name)
             logging.info(attributes)
             address = "{}, {}".format(v[5], v[3])
             res = requests.get(self.GOOGLE_GEOCODE_API, params={'components':'country:US', 'address':address, 'key':self.KEY})
             logging.info(json.dumps(res.json()))
             coords = res.json()['results'][0]['geometry']['location']
             logging.info(coords)
             geofence = {
                 "shape": "CIRCLE",
                 "radius": 100,
                 "center": {
                     "latitude": coords['lat'],
                     "longitude": coords['lng']
                 },
                 "points": None
             }
             gimbal.create_place(name=name, geofence=geofence, attributes=attributes)
Exemplo n.º 2
0
    def run(self):
        bad = []
        places = {}
        content = [f.strip() for f in open("data/Order4204.csv")]
        logging.info(content)
        count = 0
        for b in Beacon.find({'level':3}):
            b.id = b.id.replace("-", "")
            id = "{}-{}".format(b.id[:4], b.id[4:]).upper()
            logging.info(id)
            if id in content and b.place and b.place.lower() != 'duplicate':
                place_beacons = places.setdefault(slugify(b.place.lower().strip()), [])
                place_beacons.append(id)
                logging.info("Match")
            else:
                bad.append(id)
                logging.info("No Match")

        logging.info(bad)
        logging.info(json.dumps(places))
        gimbal = Gimbal(auth_key=config.GIMBAL_API_KEY)
        for k,v in places.iteritems():
            for b in v:
                name = "{}-{}".format(k, b)
                logging.info("Creating Beacon: {}".format(name))
                gimbal.create_beacon(b, name)
            logging.info("Creating Place: {}".format(k))
            gimbal.create_place(k, v)