This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
3
learning to use PRAW, but its slow
Post Flair (click to view more posts with a particular flair)
Post Body
im learning by my self how to create a reddit bot and working with API in Python, but my code is very slow. im trying to download multiple posts and their comments in order to save them and look for connections between keywords, but from what I found out im only sending a single request in every API request. how can I make this code/bot faster and be able to handle hundreds of posts at a time?
here is what im working with (removed some info and the subreddits names):
import praw
import time
import pandas as pd
import csv
reddit = praw.Reddit(client_id=<client_id>,
client_secret=<secret>,
user_agent="<Bot>",
check_for_async=False,
username=<user>,
password=<password>)
reddit.user.me()
subreddit = reddit.subreddit("....")
data = {
'PostID': [],
'Title': [],
'Text': [],
'Auther': [],
'Comments': []}
df = pd.DataFrame(data)
def getComments(submission):
for comment in submission.comments.list():
postID = submission.id
commnetAuthorID = comment.author.id
commentText = comment.body
author = "Deleted_User"
if comment.author is not None:
author = comment.author.name
addToFile('comments.csv', [postID, commnetAuthorID, author, commentText])
def newPost(postTo = '...'):
subReddit = reddit.subreddit(postTo)
postTitle = "This is a test post"
postText = "Hi, this is a post created by a bot using the PRAW library in Python :)"
subReddit.submit(title = postTitle, selftext = postText)
def addToFile(file, what, operation = 'a'):
csv.writer(open(file, operation, newline='', encoding='UTF-8')).writerow(what)
addToFile('post.csv', ['PostID', 'AuthorID', 'AuthorName', 'Title', 'Text'], 'w')
addToFile('comments.csv', ['PostID', 'AuthorID', 'AuthorName', 'Text'], 'w')
for post in subreddit.new(limit=1000):
submission = reddit.submission(id=post.id)
submission.comments.replace_more(limit=None)
getComments(submission)
author = "Deleted_User"
if post.author is not None:
author = post.author.name
addToFile('post.csv', [post.id, post.author.id ,author, post.title, post.selftext])
Author
Account Strength
90%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
3,019
Link Karma
111
Comment Karma
2,775
Profile updated: 5 days ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/redditdev/c...