0

一連のツイートを Python 2.7 の sqlite データベースにロードして、いくつかのクエリを実行する作業/学習。しかし、データを読み込むことができないようです。

データベースを作成し、テーブルを作成できますが、ツイートを読みに行くと、解析してロードします-テーブルにデータが入力されていないようです。

各ツイートで考えられる多くのフィールドのうち、6 つだけを取得しようとしています。

私のコードは次のとおりです。

#create database works fine
import sqlite3
conn = sqlite3.connect('twitter.db')
c = conn.cursor()

import urllib2
tweets=urllib2.urlopen("http://rasinsrv07.cstcis.cti.depaul.edu/CSC455/assignment4.txt")
tweets.readline()

#create table: works fine
c.execute("CREATE TABLE Tweet(created_at, id, text, source,  in_reply_to_user_ID,retweet_Count)")

#Loads variables & data in table: Not loading. I think this is my problem here.
for elt in tweets:
    currentRow = elt[:-1].split(", ")
    insert = """insert into Tweet values ('%s', '%s', '%s', '%s', '%s', '%s')""" % ("created_at", "id", "text", 'source', 'in_reply_to_user_ID', 'retweet_Count')
print insert

conn.commit()

#tried to see the table
read_tweets = """SELECT * from Tweet """
c.fetchall()

#tried again to see the table. Must be no data in the table
read_tweets = """SELECT * from Tweet """
rows = c.fetchall()

for row in rows:
    print row
4

0 に答える 0