Skip to content

Instantly share code, notes, and snippets.

@frantzmiccoli
Last active August 29, 2015 14:05
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 frantzmiccoli/23198ade1884418129b1 to your computer and use it in GitHub Desktop.
Save frantzmiccoli/23198ade1884418129b1 to your computer and use it in GitHub Desktop.
Cities filtered by size
# Data source https://www.maxmind.com/en/worldcities
# Using https://github.com/Russell91/pythonpy
# We first extract the cities with more than 500000 inhabitants
# We then filter those in relevant countries
# We generate a string close to json from the output
cat worldcitiespop.txt|py -fx --i '(int(x.split(",")[4]) > 500000)'|\
py -fx "x.split(',').pop(0) in ['us', 'it', 'es', 'pt', 'gb', 'ie', 'is', 'it', 'fr', 'ca', 'be', 'de', 'at', 'dk', 'se', 'fi', 'nl', 'no', 'ch', 'en','lu', 'pl']" |\
py -x "json.dumps({'name': x.split(',')[2], 'latitude': float(x.split(',')[5]), 'longitude': float(x.split(',')[6])}, indent=4, sort_keys=True)+','"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment