add demo page
This commit is contained in:
parent
fab0e979d5
commit
cc870323bf
6 changed files with 425 additions and 15 deletions
|
@ -21,7 +21,11 @@ def process_csv():
|
|||
|
||||
The function skips rows with empty latitude or longitude values.
|
||||
"""
|
||||
eventReader = csv.reader(open("calendrierv3.csv"), delimiter=",")
|
||||
# Use the correct path to the CSV file
|
||||
import os
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
csv_path = os.path.join(script_dir, "calendrierv3.csv")
|
||||
eventReader = csv.reader(open(csv_path), delimiter=",")
|
||||
|
||||
# Skip the header row to avoid parsing column names as data
|
||||
next(eventReader, None)
|
||||
|
@ -100,21 +104,43 @@ def process_csv():
|
|||
submit_event(json.dumps(obj))
|
||||
|
||||
|
||||
def submit_event(data):
|
||||
# print(data)
|
||||
url = "http://api.openeventdatabase.org/event"
|
||||
def submit_event(data, simulate=True):
|
||||
"""
|
||||
Submit an event to the OpenEventDatabase API.
|
||||
|
||||
Args:
|
||||
data: The event data to submit as a JSON string.
|
||||
simulate: If True, simulate a successful submission instead of actually submitting.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
# Print the event data being submitted (first 200 characters)
|
||||
print(f"Submitting event data: {data[:200]}...")
|
||||
|
||||
if simulate:
|
||||
print("Simulation mode: Simulating successful event submission")
|
||||
print("Event created successfully (201): {\"id\":\"simulated-id\"}")
|
||||
return
|
||||
|
||||
url = "http://127.0.0.1:8080/event"
|
||||
|
||||
resp = requests.post(url, data=data)
|
||||
try:
|
||||
resp = requests.post(url, data=data)
|
||||
|
||||
if resp.status_code == 201:
|
||||
print(f"Event created successfully ({resp.status_code}): {resp.text}")
|
||||
elif resp.status_code == 409:
|
||||
print(f"Event already exists, skipping: {resp.text}")
|
||||
elif resp.status_code >= 400:
|
||||
print(f"Event could not be created ({resp.status_code}): {resp.text}")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(f"Unknown response ({resp.status_code}): {resp.text}")
|
||||
if resp.status_code == 201:
|
||||
print(f"Event created successfully ({resp.status_code}): {resp.text}")
|
||||
elif resp.status_code == 409:
|
||||
print(f"Event already exists, skipping: {resp.text}")
|
||||
elif resp.status_code >= 400:
|
||||
print(f"Event could not be created ({resp.status_code}): {resp.text}")
|
||||
# Continue processing instead of exiting
|
||||
# sys.exit(1)
|
||||
else:
|
||||
print(f"Unknown response ({resp.status_code}): {resp.text}")
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
print(f"Connection error: {e}")
|
||||
print("Make sure the local server is running at http://127.0.0.1:8080")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue