簡體   English   中英

sqlite3沒有插入表

[英]sqlite3 isn't inserting into table

我一直在使用PRAW提取有關“ alot”的reddits評論。 我正在嘗試將其插入正在使用的數據庫中。

#importing praw for reddit api and time to make intervals

import praw
import time
import re
import sqlite3

username = "LewisTheRobot"
password = ""

conn = sqlite3.connect('alotUsers')
c = conn.cursor()
r = praw.Reddit(user_agent = "Counts people who say alot")

word_to_match = [r'\balot\b']

storage = []

r.login(username, password)

def run_bot():
    subreddit = r.get_subreddit("all")
    print("Grabbing subreddit")
    comments = subreddit.get_comments(limit=200)
    print("Grabbing comments")
    for comment in comments:
        comment_text = comment.body.lower()
        isMatch = any(re.search(string, comment_text) for string in word_to_match)
        if comment.id not in storage and isMatch and comment.author not in storage:
            print("Match found! Storing username: " + str(comment.author) + " into list.")
            storage.append(comment.author)
            c.execute("INSERT INTO alot (id, username) VALUES(?, ?)", (str(comment.id), str(comment.author)))
            conn.commit

    print("There are currently: " + str(len(storage)) + " people who use 'alot' instead of ' a lot'.")


while True:
    run_bot()
    time.sleep(5)

目前,它已添加到列表中,並找到了很多提示。 但是,沒有任何錯誤消息,它不會添加到我的數據庫中。 數據庫名稱是alotUsers,表是很多。

檢查conn.commit 你不承諾。

conn.commit是一個函數,執行conn.commit()對我conn.commit() 謝謝@Cameron

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM