Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:46:22+00:00 2026-06-15T17:46:22+00:00

I’ll get right into it – I first created a local db for myself:

  • 0

I’ll get right into it – I first created a local db for myself:

import sqlite3

conn = sqlite3.connect("tofire.db") #

cursor = conn.cursor()

# create a table

cursor.execute("""CREATE TABLE incidents
                  (Id INTEGER PRIMARY KEY, prime_street text, cross_street text, dispatch_time text, 
                   incident_number text, incident_type text, alarm_level text, area text, dispatched_units text, date_added text)
               """)

This went without a hitch – the next part is my function, and it uses beautiful soup to scrape a table into a list of lists. I am then attempting to write the information in each sublist to the sqlite database.

# Toronto Fire Calls

import urllib2
import sqlite3
import time
import csv
import threading
from bs4 import BeautifulSoup

# Beautiful Soup imports the URL as html
def getincidents ():

    response = urllib2.urlopen('http://www.toronto.ca/fire/cadinfo/livecad.htm')

    html = response.read()

    # We give the html its own variable.

    soup = BeautifulSoup(html)

    # Find the table we want on the Toronto Fire Page

    table = soup.find("table", class_="info")

    # Find all the <td> tags in the table and assign them to variable.

    cols = table.find_all('td')

    # Find the length of rows, which is the number of <font> tags, and assign it to a variable num_cols.

    num_cols = len(cols)

    # Create an empty list to hold each of the <font> tags as an element

    colslist = []
    totalcols = 0
    # For each <font> in cols, append it to colslist as an element.

    for col in cols:
        colslist.append(col.string)
        totalcols = len(colslist)

    # Now colslist has every td as an element from [0] to totalcols = len(colslist)

    # The First 8 <font> entries are always the table headers i.e. Prime Street, Cross Street, etc.

    headers = colslist[0:8]

    # Prime Street
    # Cross Street
    # Dispatch Time
    # Incident Number
    # Incident Type
    # Alarm Level
    # Area
    # Dispatched Units

    # Get the indexes from 0 to the length of the original list, in steps of list_size, then create a sublist for each.
    # lists = [original_list[i:i+list_size] for i in xrange(0, len(original_list), list_size)]
    list_size = 8
    i = 0
    incidents = [colslist[i:i+list_size] for i in xrange(0, len(colslist), list_size)]

    # Works!

    num_inci = len(incidents) # Get the number of incidents
    added = time.strftime("%Y-%m-%d %H:%M")
    update = 'DB Updated @ ' + added

    # SQL TIME, Connect to our db.
    conn = sqlite3.connect("tofire.db")
    cursor = conn.cursor()
    lid = cursor.lastrowid

    # Now we put each incident into our database.

    for incident in incidents[1:num_inci]:
        incident.append(added)
        to_db = [(i[0:10]) for i in incident]
        import ipdb; ipdb.set_trace()
        cursor.executemany("INSERT INTO incidents (prime_street, cross_street, dispatch_time, incident_number, incident_type, alarm_level, area, dispatched_units, date_added) VALUES (?,?,?,?,?,?,?,?,?)", to_db)
    conn.commit()
    print update
    print "The last Id of the inserted row is %d" % lid
    threading.Timer(300, getincidents).start()

getincidents()

I always end up with error message “Incorrect Number of Bindings Supplied” – and it claims that I’m trying to use 9 in my statement when 10 are supplied. I’ve tried to narrow down the cause of this, but have had no success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:46:23+00:00Added an answer on June 15, 2026 at 5:46 pm

    As Ned Batchelder recently put it, “First Rule of Debugging: When in Doubt, Print More Out.” After you append added to incident, incident itself has 9 items in it:

    print(incident)
    # [u'NORFINCH DR, NY', u'FINCH AVE W / HEPC', u'2012-12-09 17:32:57', u'F12118758', u'Medical - Other', u'0', u'142', u'\r\nP142, \r\n\r\n', '2012-12-09 17:46']
    

    So it looks like all you really need to do is use incident as the second argument to cursor.execute. Or, if you want to get rid of some of that whitespace around items like u'\r\nP142, \r\n\r\n',
    you could use

        to_db = [i.strip() for i in incident]
    

    for incident in incidents[1:num_inci]:
        incident.append(added)
        to_db = [i.strip() for i in incident]
        import ipdb; ipdb.set_trace()
        cursor.execute(
            """INSERT INTO incidents
               (prime_street, cross_street, dispatch_time, incident_number,
                incident_type, alarm_level, area, dispatched_units, date_added)
               VALUES (?,?,?,?,?,?,?,?,?)""", to_db)
        lid = cursor.lastrowid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.