Reputation: 1186
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.
Upvotes: 0
Views: 49
Reputation: 1186
conn.commit
is a function and doing conn.commit()
worked for me. Thank you @Cameron
Upvotes: 0