Rename fetch data script & add check for empty posts
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
import json
|
import json
|
||||||
from connectors.reddit_connector import RedditConnector
|
from connectors.reddit_connector import RedditConnector
|
||||||
|
|
||||||
data_file = 'reddit_posts.json'
|
data_file = 'data/reddit_posts.json'
|
||||||
reddit_connector = RedditConnector()
|
reddit_connector = RedditConnector()
|
||||||
|
|
||||||
|
def remove_empty_posts(posts):
|
||||||
|
return [post for post in posts if post.content.strip() != ""]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
posts = reddit_connector.get_new_subreddit_posts('cork', limit=1000)
|
posts = reddit_connector.get_new_subreddit_posts('cork', limit=1000)
|
||||||
|
posts = remove_empty_posts(posts)
|
||||||
|
|
||||||
print(f"Fetched {len(posts)} posts from r/cork")
|
print(f"Fetched {len(posts)} posts from r/cork")
|
||||||
|
|
||||||
with open(data_file, 'w') as f:
|
with open(data_file, 'w') as f:
|
||||||
Reference in New Issue
Block a user