https://github.com/marceloprates/prettymaps "presents": barcelona barcelona-plotter…
- User
https://github.com/marceloprates/prettymaps
"presents": barcelona barcelona-plotter cb-bf-f default heerhugowaard macao minimal tijuca
create a python script that loops for every available present (0-7) for a cityname that i will save in a .txt but the coordinates have to be searched on openstreetmaps first create error handling
- Assistant
First, make sure you have the necessary dependencies installed:
pip install osmnx pretty-mapsThen, create a Python script with the following code:
import os import osmnx as ox from prettymaps import plot_coordinates from IPython.display import SVG, display city_name = input("Enter city name: ") # Function to get coordinates from city name def get_coordinates(city): try: location = ox.geocode(city) return location except Exception as e: print(f"Error getting coordinates: {e}") return None # Get the location coordinates coordinates = get_coordinates(city_name) if coordinates is not None: # List of available presets presets = ['barcelona', 'barcelona-plotter', 'cb-bf-f', 'default', 'heerhugowaard', 'macao', 'minimal', 'tijuca'] # Loop through each preset and save the map as an SVG file for preset in presets: try: fig, ax = plot_coordinates(coordinates, figsize=(5,5), watermark='{}\n{}'.format(city_name, preset), style=preset) svg_filename = f'{city_name}_{preset}.svg' fig.savefig(svg_filename, format='svg') print(f"{svg_filename} saved") display(SVG(svg_filename)) except Exception as e: print(f"Error plotting prettymaps with preset {preset}: {e}") else: print("Could not get the coordinates for the given city name.") - User
input the city_name from a .txt and loop through every line
- Assistant
To input the city name from a .txt file and loop through every line, modify the script as follows:
import os import osmnx as ox from prettymaps import plot_coordinates from IPython.display import SVG, display # Function to get coordinates from city name def get_coordinates(city): try: location = ox.geocode(city) return location except Exception as e: print(f"Error getting coordinates: {e}") return None # Read city names from the file with open('city_names.txt', 'r') as file: city_names = file.readlines() # Remove newline characters from city names city_names = [city.strip() for city in city_names] # Loop through each city name in the file for city_name in city_names: # Get the location coordinates coordinates = get_coordinates(city_name) if coordinates is not None: # List of available presets presets = ['barcelona', 'barcelona-plotter', 'cb-bf-f', 'default', 'heerhugowaard', 'macao', 'minimal', 'tijuca'] # Loop through each preset and save the map as an SVG file for preset in presets: try: fig, ax = plot_coordinates(coordinates, figsize=(5,5), watermark='{}\n{}'.format(city_name, preset), style=preset) svg_filename = f'{city_name}_{preset}.svg' fig.savefig(svg_filename, format='svg') print(f"{svg_filename} saved") display(SVG(svg_filename)) except Exception as e: print(f"Error plotting prettymaps with preset {preset}: {e}") else: print(f"Could not get the coordinates for the city name: {city_name}")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.