def _handle_locations_notification(self, data): """Handle locations notification.""" Dwolla = DwollaClientApp(_keys.apiKey, _keys.apiSecret) location = self.mirror_service.locations().get(id=data['itemId']).execute() loc = 'dg-' + str(round(location.get('latitude'), 3)) + 'x' + str(round(location.get('longitude'), 3)) logging.info('Your loc is ' + loc) items = self.mirror_service.timeline().list().execute() loc_exists = False for i in items['items']: # FIXME: need to not send down items every 10 minutes # if i['bundleId'] == loc: # loc_exists = True # logging.info('parsed date') # try: # logging.info(parse_date(i['created'])) # except: # pass # logging.info(type(i['created'])) # logging.info('current time plus 5:') # logging.info(datetime.now() + timedelta(minutes=5)) # if i['created'] < (datetime.now() + timedelta(minutes=5)): # loc_exists = False # if loc_exists == False: spots = Dwolla.get_nearby_spots()#lat=location.get('latitude'), lon=location.get('longitude')) for spot in spots: html = """<article><section class="align-center text-auto-size"><p>%s is nearby.</p></section><footer class="align-center">eyepay</footer></article>""" % (spot['Name']) logging.info('Inserting timeline item') body = { "html": html, "bundleId": loc, "menuItems": [], "notification": { "level": "DEFAULT" } } amt = 0 while amt < 1: amt += 0.01 id_text = str(amt) + "@" + spot['Id'] body['menuItems'].append({ "action": "CUSTOM", "id": id_text, "values": [{ "displayName": "Pay $%s" % (amt), "iconUrl": "http://upload.wikimedia.org/wikipedia/commons/e/ec/Blank_50px.png" }] }) self.mirror_service.timeline().insert(body=body).execute()
# Parse JSON response for lat/lon pair try: js = json.loads(str(data)) except: js = None if 'status' not in js or js['status'] != 'OK': print '==== Failure To Retrieve ====' print data quit() else: latVal = js['results'][0]['geometry']['location']['lat'] lonVal = js['results'][0]['geometry']['location']['lng'] # Query Dwolla for spots near the address DwollaClient = DwollaClientApp(key, secret) radius = 2 spots = DwollaClient.get_nearby_spots(latVal, lonVal, radius, maxHits) # If there are fewer results than the user-specified maximum, query again over a # larger radius while (len(spots) < maxHits) and (radius < 50): radius = radius * 5 spots = DwollaClient.get_nearby_spots(latVal, lonVal, radius, maxHits) # Output the results print('The ' + str(len(spots)) + ' closest spots that accept Dwolla are:\n') rVal = range(0,len(spots)) for index in rVal: # Convert the delta parameter (which seems to be Earth Central Angle in degrees) into miles distVal = round( ( (spots[index]['Delta'] * math.pi / 180) * 6378 * 0.62 ), 2) print (spots[index]['Name'] + '\n' + string.rstrip(spots[index]['Address'], '\n') + '\n' + spots[index]['City'] +