'why didn't my program write some of the fields?
So I wrote a program to write the different attributes like title, total number of comments, total upvotes, post body, author name of submissions in a CSV file. Code:
class ptdata(Thread):
def run(self):
print('opening post_data csv')
with open('post_data.csv', 'a') as f:
headers = [
'ID', 'Date_utc', 'Upvotes', 'Number of Comments', 'Subthread name', 'Post Author'
]
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,
"Post Auther": post.author
}
writer.writerow(data)
print('writing post row')
# print(data)
But when I looked into the data it wrote:
ID Date_utc Upvotes Number of Comments Subthread name Post Author
0 sw73ml 1645266563.0 2 NaN I fucking love cars, but actually driving, or ... NaN
1 sw73sa 1645266581.0 3 NaN It's my birthday!!!! NaN
2 sw73va 1645266588.0 3 NaN My bike just got stolen NaN
3 sw73x0 1645266593.0 4 NaN I feel like an outsider socially NaN
4 sw75gk 1645266754.0 10 NaN Hallo? Ist dis Bert und Ernie’s BDSM emporium? NaN
... ... ... ... ... ... ...
7703 uou8wd 1652455643.0 2 NaN Holy crap I forgot how good… NaN
7704 uou8yy 1652455648.0 4 NaN Just got told to kill myself NaN
7705 uou8zv 1652455650.0 4 NaN hey YOU NaN
7706 uouagi 1652455771.0 1 NaN STEVEN UNIVERSE IS GREAT NaN
7707 uouaks 1652455780.0 1 NaN drinking water after chewing gum is the cold e... NaN
it is something like this. As you can see it shows NaN in the number of comments and post author column. But When I looked at a different CSV file for which I used the same code, it had written the Author name but not the number of comments.
why is this happening?
Also is there any way to get all that data back? because this bot is running for more than 3 months now and without this information this data is kinda useless
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
