-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Description
I have this (somewhat) working script that takes comments from a Reddit subreddit and insert them into a MySQL database. The spaghetti code I ended up with, however, pastes one character from each comment to each row of the database instead of one comment per row.
Screenshot: https://ibb.co/k0jNd59
import praw
import configReddit
import mysql.connector
import configMySQL
# ---------------- REDDIT ---------------- #
reddit = praw.Reddit(
client_id=configReddit.client_id,
client_secret=configReddit.client_secret,
password=configReddit.password,
user_agent=configReddit.user_agent,
username=configReddit.username,
charset='utf8mb4'
)
# ---------------- DATABASE ---------------- #
mydb = mysql.connector.connect(
host=configMySQL.host,
user=configMySQL.user,
password=configMySQL.password,
database="db_blockchainstable",
)
mycursor = mydb.cursor()
sql = "INSERT INTO test (rdtext) VALUES (%s)"
# ---------------- EXE ---------------- #
for comment in reddit.subreddit("CryptoCurrency+BitcoinMarkets+CryptoCurrencies+cryptomarkets+cryptocurrencytrading+cryptotrading+ethrader+Crypto_Currency_News").stream.comments():
rdtext = str(comment.body)
db = (rdtext)
mycursor.executemany(sql, db)
mydb.commit()
print(comment.body)`Metadata
Metadata
Assignees
Labels
No labels