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

  • SEARCH
  • Home
  • 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 6907345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:25:23+00:00 2026-05-27T08:25:23+00:00

Code: import time import tweepy import sqlite3 class Listener(tweepy.StreamListener): conn = sqlite3.connect(‘/home/daniel/Desktop/activeSites/djeep/djeep.db’) def on_status(self,

  • 0

Code:

import time
import tweepy
import sqlite3

class Listener(tweepy.StreamListener):

    conn = sqlite3.connect('/home/daniel/Desktop/activeSites/djeep/djeep.db')

    def on_status(self, status):
        try:
            c = self.conn.cursor()
            c.execute("""insert into feed_post values (%r,'%s','%s',%d)""") % (status.id, status.text, status.author.screen_name, status.created_at)
            self.conn.commit()
        except:
            pass


    def on_error(self, status_code):
        print 'An error has occured! Status code = %s' % status_code
        return True  # keep stream alive

    def on_timeout(self):
        print 'timeout...'

def main():
    auth = tweepy.OAuthHandler('C_KEY', 'C_SECRET') 
    auth.set_access_token('ACCESS_TOKEN', 'ACCESS_SECRET') 
    stream = tweepy.Stream(auth=auth, listener=Listener())     
    stream.filter(track=('baseball',)) 

if __name__=="__main__":
    try:
        main()
    except KeyboardInterrupt:
        print "See ya!"

I’ve gone back and added one line of the database related code at a time to try and find out what breaks it, and it seems to be the addition of the c.execute() line. I just can’t figure out what I’m missing!

  • 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-05-27T08:25:24+00:00Added an answer on May 27, 2026 at 8:25 am

    The path to the database should be an argument to your script, not hardcoded. It should be supplied to your class each time the class is instantiated, NOT when your class is created. However it’s not apparent that that is the cause of your problem, not yet exactly what the problem is:

    Your title indicates that you can’t get anything written to your database, but the question body implies that something “breaks” when you add in c.execute — which is correct? What are the symptoms when it “breaks”?

    Your try\yadda\except\pass is silently ignoring all possible exceptions — don’t do that! Remove the try\except\pass leaving only the yadda, answer the above questions, and let us know the outcome.

    UPDATE: Your c.execute() statement is a shocker. Making it legible without scrolling, it’s equivalent to this:

    (
        c.execute("""insert into feed_post values (%r,'%s','%s',%d)""")
        % 
        (status.id, status.text, status.author.screen_name, status.created_at)
    )
    

    In other words, you have a right parenthesis grossly misplaced. The result is syntactically valid, but is sure to cause an exception at run time.

    Worse: you are setting yourself up for an SQL injection attack. Use parameters instead of string formatting:

    sql = "insert into feed_post values (?,?,?,?)"
    params = (status.id, status.text, status.author.screen_name, status.created_at)
    c.execute(sql, params)
    

    A bonus from this approach is that it should run much faster, as the engine will not need to parse (or have its cache swamped by) a typically-different SQL statement for each row written.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from getpass import getpass from textwrap import TextWrapper import tweepy import time class StreamWatcherListener(tweepy.StreamListener):
Basically I have the following code: import multiprocessing import time class MyProcess(multiprocessing.Process): def __init__(self,
The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite;
Code: import com.independentsoft.exchange.Service; import android.app.Activity; import android.os.Bundle; public class ContactsToExchangeActivity extends Activity { @Override
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
So I found this code: #!/usr/bin/python import sys #for cmd line argv import time
I have the code below ; import cv import time cv.NamedWindow(camera, 1) capture =
I solved Project Euler #14 using the following code: import time start_time = time.time()
I have this sample of code: import sys import time from PyQt4.QtGui import *
Here is my code: import matplotlib.pyplot as plt plt.loglog(length,time,'--') where length and time are

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.