Skip to content

Commit

Permalink
Get cities.csv from website if not present.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Bloedow committed Jun 19, 2024
1 parent b39d320 commit 4484a1e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions jb/utils/folium_animate_from_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import sqlite3
import random
import numpy as np
import sys
import requests
import os
import argparse
import os

Expand All @@ -27,12 +28,27 @@ def preproc( sim_report_file ):
cursor.executemany(f"INSERT INTO engwal VALUES ({', '.join(['?' for _ in headers])})", reader)

# Import cities.csv into cities table
with open('cities.csv', 'r') as file:
reader = csv.reader(file)
if os.path.exists( 'cities.csv' ):
with open('cities.csv', 'r') as file:
reader = csv.reader(file)
headers = next(reader)
cursor.execute(f"CREATE TABLE cities ({', '.join(headers)})")
cursor.executemany(f"INSERT INTO cities VALUES ({', '.join(['?' for _ in headers])})", reader)
else:
url = 'https://packages.idmod.org:443/artifactory/idm-data/laser/cities.csv'

# Perform an HTTP GET request
response = requests.get(url)
response.raise_for_status() # Check that the request was successful

# Process the CSV file directly from the response content
content = response.content.decode('utf-8').splitlines()
reader = csv.reader(content)
headers = next(reader)
cursor.execute(f"CREATE TABLE cities ({', '.join(headers)})")
cursor.executemany(f"INSERT INTO cities VALUES ({', '.join(['?' for _ in headers])})", reader)


# Create the view
cursor.execute("""
CREATE VIEW cases AS
Expand Down

0 comments on commit 4484a1e

Please sign in to comment.