0

I have been using PRAW to pull reddits comments that say 'alot'. I am trying to insert it into the database that I am using.

#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)

Currently it adds to the list and finds reddit comments that says alot. However, without any error message it doesn't add to my database. database name is alotUsers and table is alot.

1
  • conn.commit is a function. You retrieve it, but never call it. Use conn.commit() instead. Commented Jan 22, 2015 at 20:02

2 Answers 2

1

Check conn.commit . You don't commit.

Sign up to request clarification or add additional context in comments.

Comments

0

conn.commit is a function and doing conn.commit() worked for me. Thank you @Cameron

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.