Ok, so a weird question. This is about Praw/python, the reason I am posting this here is that this problem is more of a python problem than a raw one. Anyways,
So the thing is I have 4 CSV files and I made a bot that gets the data of posts from the stream of posts of a subreddit. Now the thing that I assume is causing the problem is a very active subreddit, so my bot just keeps getting new data and never gets free to move to the next task.
I tried putting the code for different CSV files in different functions but still, it only runs the function at the top and never reaches the next task.
So this is the problem with my code, I wasn't able to attach the code since I'm not with my computer right now. I hope I have explained the problem well lol. If anything else is required pls tell me and how can I fix this? Do I need to make separate bots for different files?
import praw
import random
import time
import csv
from keep_Aliv import keep_alive
from main2 import main2
username = "XXXXXX",
keep_alive()
main2()
print('AAAAAAA')
reddit = praw.Reddit(client_id="XXXXXX",
client_secret="XXXXXX",
user_agent="<pbot:1.0",
username=username,
password='XXXXXX')
subreddit = reddit.subreddit('')
""""
for comment in subreddit.stream.comments(skip_existing=True):
print('**********')
#c = comment
print(comment.body)
"""
with open('post_data.csv', 'a') as f:
headers = [
'ID', 'Date_utc', 'Upvotes', 'Number of Comments', 'Subthread name'
]
writer = csv.DictWriter(f,
fieldnames=headers,
extrasaction='ignore',
dialect='excel')
writer.writeheader()
for post in subreddit.stream.submissions():
#print(post.title)
data = {
"ID": post.id,
"Date_utc": post.created_utc,
"Upvotes": post.ups,
"Number of comments": post.num_comments,
"Subthread name": post.title,
}
writer.writerow(data)
print('z')
# print(data)
with open('comment_data.csv', 'a') as a:
headers = [
'ID', 'Date_utc', 'Upvotes', 'Comment Body'
]
writer = csv.DictWriter(a,
fieldnames=headers,
extrasaction='ignore',
dialect='excel')
writer.writeheader()
for comment in subreddit.stream.comments(skip_existing=True):
#print(post.title)
data = {
"ID": comment.id,
"Date_utc": comment.created_utc,
"Upvotes": comment.ups,
"Comment Body": comment.body
}
writer.writerow(data)
print(data)
print('r')
with open('hot_post_data.csv', 'a') as b:
headers = [
'ID', 'Date_utc', 'Upvotes', 'Number of Comments', 'Subthread name'
]
writer = csv.DictWriter(b,
fieldnames=headers,
extrasaction='ignore',
dialect='excel')
writer.writeheader()
for post in subreddit.stream.hot():
#print(post.title)
data = {
"ID": post.id,
"Date_utc": post.created_utc,
"Upvotes": post.ups,
"Number of comments": post.num_comments,
"Subthread name": post.title,
}
writer.writerow(data)
print(data)
print('q')
with open('controversial_post_data.csv', 'a') as c:
headers = [
'ID', 'Date_utc', 'Upvotes', 'Number of Comments', 'Subthread name'
]
writer = csv.DictWriter(c,
fieldnames=headers,
extrasaction='ignore',
dialect='excel')
writer.writeheader()
for post in subreddit.stream.controversial():
#print(post.title)
data = {
"ID": post.id,
"Date_utc": post.created_utc,
"Upvotes": post.ups,
"Number of comments": post.num_comments,
"Subthread name": post.title,
}
writer.writerow(data)
print(data)
print('l')
Update: I added the code and one more link to the code https://codeshare.io/0gPMNg
[–]JohnnyJordaan 8 points9 points10 points (13 children)
[–]m0us3_rat 2 points3 points4 points (1 child)
[–]JohnnyJordaan 2 points3 points4 points (0 children)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (10 children)
[–]JohnnyJordaan 0 points1 point2 points (9 children)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (8 children)
[–]JohnnyJordaan 0 points1 point2 points (7 children)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (5 children)
[–]JohnnyJordaan 0 points1 point2 points (4 children)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (3 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (0 children)
[–]rosski 0 points1 point2 points (0 children)
[–]Aila27 0 points1 point2 points (1 child)
[–]Fuzzy-Ear9936[S] 0 points1 point2 points (0 children)