Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################################################################################################################
- # File: main.py
- # Author: Dan Huckson, https://github.com/unodan
- # Date: 2018-12-09
- ########################################################################################################################
- from json import load, dump
- cities_source = 'cities.json'
- states_source = 'states.json'
- countries_source = 'countries.json'
- cities = {"cities": []}
- states = {"states": []}
- countries = {"countries": []}
- countries_ids = (38, 230, 231)
- cities_output = 'cities_file.json'
- states_output = 'states_file.json'
- countries_output = 'countries_file.json'
- with open(countries_source, 'r') as c:
- data = load(c)
- for country in data['countries']:
- if int(country['id']) in countries_ids:
- countries['countries'].append(country)
- with open(states_source, 'r') as s:
- data = load(s)
- for state in data['states']:
- if int(state['country_id']) == int(country['id']):
- states['states'].append(state)
- with open(cities_source, 'r') as t:
- data = load(t)
- for city in data['cities']:
- if int(city['state_id']) == int(state['id']):
- cities['cities'].append(city)
- print(country['name'], state['name'], city['name'])
- with open(countries_output, 'w') as f:
- dump(countries, f, indent=4)
- with open(states_output, 'w') as f:
- dump(states, f, indent=4)
- with open(cities_output, 'w') as f:
- dump(cities, f, indent=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement