def iterateResponsesStarting(start_address_key): key_err = False facebookapi = FacebookApi() facebookapi.generateAccessToken() tableiter = TableIterator(TABLENAME) last_response = start_address_key nextResponse = tableiter.batchGetItemWithName(ATTRIBUTES, last_response) while key_err == False: for response in nextResponse['Items']: print("response", response) facebookNames = facebookapi.facebookSearchName(response['name']) try: for name in facebookNames['data']: print(name) facebookAddress = facebookapi.facebookGetAddress(name['id']) try: print(facebookAddress['location']['street'], " || ", response['location']['display_address'][0]) if addressEquals(facebookAddress['location']['street'], response['location']['display_address'][0]): totalIdCount += 1 print("=================match on next response: ", totalIdCount) tableiter.updateItemSet(response['address_key'], 'facebook_id', name['id']) break except Exception: try: parentId = facebookAddress['location']['located_in'] facebookAddress = facebookapi.facebookGetAddress(parentId) print("second try: ", facebookAddress) if facebookAddress['location']['street'] == response['location']['display_address'][0]: totalIdCount += 1 print("=================match on next parent: ", totalIdCount) tableiter.updateItemSet(response['address_key'], 'facebook_id', name['id']) break except Exception: pass pass except KeyError: pass tableiter.narcolepsy() try: last_response = nextResponse['LastEvaluatedKey'] print("last response", last_response) nextResponse = tableiter.batchGetItemWithName(ATTRIBUTES, last_response) except KeyError: keyErr = True print("Done!")