Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
software-project-WS25
Reddit Team
Commits
4d55a5dd
Commit
4d55a5dd
authored
Oct 24, 2025
by
Benavides Ontiveros
Browse files
reddit data fetch with PRAW library test 1
parent
432e3cce
Changes
1
Show whitespace changes
Inline
Side-by-side
app.py
View file @
4d55a5dd
import
praw
import
json
# Reddit API credentials
reddit
=
praw
.
Reddit
(
client_id
=
""
,
client_secret
=
""
,
user_agent
=
"MyRedditApp/0.1 by DevTest0"
)
# Choose your subreddit
subreddit
=
reddit
.
subreddit
(
"soccer"
)
# Get a subreddit object (e.g., "python")
subreddit
=
reddit
.
subreddit
(
'python'
)
# Extract some useful data into a dictionary
subreddit_data
=
{
"id"
:
subreddit
.
id
,
"display_name"
:
subreddit
.
display_name
,
"title"
:
subreddit
.
title
,
"description"
:
subreddit
.
public_description
,
"subscribers"
:
subreddit
.
subscribers
,
"created_utc"
:
subreddit
.
created_utc
,
"over18"
:
subreddit
.
over18
,
"url"
:
subreddit
.
url
,
# Add more fields if you want
}
# Convert to JSON string
json_data
=
json
.
dumps
(
subreddit_data
,
indent
=
4
)
print
(
json_data
)
# Fetch top 5 hot posts
for
post
in
subreddit
.
hot
(
limit
=
2
):
print
(
f
"
\n
Post Title:
{
post
.
title
}
"
)
print
(
f
"URL:
{
post
.
url
}
"
)
print
(
"Comments:"
)
# Load all comments
post
.
comments
.
replace_more
(
limit
=
0
)
# This removes "MoreComments" placeholders
for
comment
in
post
.
comments
[:
5
]:
# Limit to top 5 comments
print
(
f
"-
{
comment
.
body
[
:
200
]
}
"
)
# Print first 100 characters of comment
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment