Close

May 17th v0.3 code with MySQL

A project log for whosthatbird

Pi-based platform to photograph and record birds, and classify them at both species and individual level

neil-k-sheridanNeil K. Sheridan 05/17/2025 at 18:510 Comments

Today I added a MySQL database, and updated code so that the images and accompanying species ID are sent to the database! First we needed to fetch just the species name from the dict which contains all the classification information (e.g. probability etc.): species_name = species["predicted_class"]

CREATE DATABASE whosthatbird;
USE whosthatbird;

CREATE TABLE bird_sightings (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    image_path VARCHAR(255) NOT NULL,
    species VARCHAR(100) NOT NULL,
    timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);

Then, I added the code to insert to the MySQL table in the annotate_photo module (for now):


#let's put the code for insert to MySQL table here
    timestamp = datetime.now()    
    #connect to DB
    conn = mysql.connector.connect(
        host="localhost",
        user="user",
        password="password",
        database="whosthatbird"
    )
    
    cursor = conn.cursor()
    cursor.execute(
        "INSERT INTO bird_sightings (image_path, species, timestamp) VALUES (%s, %s, %s)",
        (image_path, species_name, timestamp)
    )    

    
    conn.commit()
    cursor.close()
    conn.close()

Discussions