Skip to content

Instantly share code, notes, and snippets.

@jonathanvx
Created November 14, 2018 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanvx/681878780276e44a598331b9c426e781 to your computer and use it in GitHub Desktop.
Save jonathanvx/681878780276e44a598331b9c426e781 to your computer and use it in GitHub Desktop.
Filtering JSONs
import timeout_filter as tf
def test_timeout_filter():
#TODO: create fake data with expected results from timeout_filter
test_data_users = "{ }"
test_data_venues= "{ }"
print tf.filter_venues(test_data_users, test_data_venues)
#TODO: compare filter results with expected results
if __name__ == "__main__" :
test_timeout_filter()
import json
import io
def load_users():
with open('users.json') as users_data:
return json.load(users_data)
def load_venues():
with open('venues.json') as venues_data:
return json.load(venues_data)
def filter_venues(users,venues):
places_to_avoid = dict()
places_to_go = list()
for i in range(0, len(venues)):
place_to_go = True
for j in range(0, len(users)):
if len(set(venues[i]['food']).intersection(users[j]['wont_eat'])) > 0 :
places_to_avoid[venues[i]['name']] = 'There is nothing for ' + users[j]['name'] + ' to eat'
place_to_go = False
break
if len(set(venues[i]['drinks']).intersection(users[j]['drinks'])) == 0 :
places_to_avoid[venues[i]['name']] = 'There is nothing for ' + users[j]['name'] + ' to drink'
place_to_go = False
break
if place_to_go == True :
places_to_go.insert = venues[i]['name']
return(places_to_go,places_to_avoid)
def main():
print filter_venues(load_users(), load_venues())
if __name__ == "__main__" :
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment