Take a copy of the
TM_WORLD_BORDERS-0.3 directory you downloaded earlier, and place it inside your
world_borders directory. Then create another Python script named
import_data.py. This is where you will place the code to import the data into your database.
We are going to use the OGR library to import the data from the shapefile, and
psycopg2 to insert it into the database. So the first two lines in our program should look like the following:
import osgeo.ogr import psycopg2
We next need to open up a connection to the database. The code to do this is identical to the code that we used in the
connection = psycopg2.connect(database="world_borders", user="...", password="...") cursor = connection.cursor() ...