-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_data_script.py
More file actions
27 lines (21 loc) · 834 Bytes
/
add_data_script.py
File metadata and controls
27 lines (21 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import json
# Prompt the user for the place name and coordinates
place_name = input("Enter the name of the place: ")
coordinates_input = input("Enter the coordinates (lat,lon): ")
# Split the input coordinates into latitude and longitude
latitude, longitude = coordinates_input.split(',')
# Load the existing JSON data
with open("eafit-campus-locations.json", "r", encoding='utf-8') as json_file:
data = json.load(json_file)
# Append the new place to the "places" array
data["places"].append({
"name": place_name,
"coordinates": {
"latitude": float(latitude),
"longitude": float(longitude)
}
})
# Write the updated data back to the JSON file
with open("eafit-campus-locations.json", "w", encoding='utf-8') as json_file:
json.dump(data, json_file, indent=4)
print("Place added successfully!")