process.py 657 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import sys
  3. import csv
  4. """
  5. Strip unneeded data from world cities database.
  6. https://simplemaps.com/data/world-cities
  7. """
  8. us_cities = []
  9. other_cities = []
  10. with open(sys.argv[1]) as infile:
  11. reader = csv.reader(infile, quotechar='"')
  12. next(reader) # skip header
  13. for row in reader:
  14. pt = (row[2], row[3])
  15. if row[4] == "United States":
  16. us_cities.append(pt)
  17. else:
  18. other_cities.append(pt)
  19. with open(sys.argv[2], "w") as outfile:
  20. for (lat, lng) in us_cities:
  21. outfile.write(f"{lat}, {lng}\n")
  22. with open(sys.argv[3], "w") as outfile:
  23. for (lat, lng) in other_cities:
  24. outfile.write(f"{lat}, {lng}\n")