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
b1bdf098
Commit
b1bdf098
authored
Dec 15, 2025
by
Benavides Ontiveros
Browse files
add extra fields for data
parent
fcb9e09c
Changes
1
Hide whitespace changes
Inline
Side-by-side
app.py
View file @
b1bdf098
...
...
@@ -79,14 +79,36 @@ for subreddit_name in subreddit_list:
except
Exception
as
e
:
logger
.
warning
(
f
"Comments for post
{
post
.
id
}
not fully loaded:
{
e
}
"
)
# --- Vote / polarization calculations ---
score
=
post
.
score
upvote_ratio
=
post
.
upvote_ratio
estimated_upvotes
=
None
estimated_downvotes
=
None
vote_polarization
=
None
if
upvote_ratio
is
not
None
and
upvote_ratio
!=
0.5
:
try
:
total_votes
=
score
/
(
2
*
upvote_ratio
-
1
)
estimated_upvotes
=
int
(
total_votes
*
upvote_ratio
)
estimated_downvotes
=
int
(
total_votes
*
(
1
-
upvote_ratio
))
vote_polarization
=
abs
(
0.5
-
upvote_ratio
)
*
2
except
ZeroDivisionError
:
pass
try
:
post_data
=
{
"id"
:
post
.
id
,
"title"
:
post
.
title
,
"score"
:
post
.
score
,
"score"
:
score
,
"upvote_ratio"
:
upvote_ratio
,
"estimated_upvotes"
:
estimated_upvotes
,
"estimated_downvotes"
:
estimated_downvotes
,
"vote_polarization"
:
vote_polarization
,
"url"
:
post
.
url
,
"num_comments"
:
post
.
num_comments
,
"created_utc"
:
post
.
created_utc
,
"created_iso"
:
datetime
.
fromtimestamp
(
post
.
created_utc
,
timezone
.
utc
).
isoformat
(),
"comments"
:
[]
}
except
Exception
as
e
:
...
...
@@ -106,7 +128,8 @@ for subreddit_name in subreddit_list:
"id"
:
comment
.
id
,
"body"
:
comment
.
body
,
"score"
:
comment
.
score
,
"created_utc"
:
comment
.
created_utc
"created_utc"
:
comment
.
created_utc
,
"created_iso"
:
datetime
.
fromtimestamp
(
comment
.
created_utc
,
timezone
.
utc
).
isoformat
()
})
except
Exception
as
e
:
logger
.
warning
(
f
"Failed to parse a comment in post
{
post
.
id
}
:
{
e
}
"
)
...
...
@@ -121,6 +144,7 @@ for subreddit_name in subreddit_list:
# --- Generate Unix timestamp in milliseconds for unique file names ---
timestamp_ms
=
int
(
datetime
.
now
(
timezone
.
utc
).
timestamp
()
*
1000
)
timestamp_iso
=
datetime
.
now
(
timezone
.
utc
).
isoformat
()
# Output data file
data_filename
=
os
.
path
.
join
(
OUTPUT_DIR
,
f
"reddit_
{
subreddit_name
}
_
{
timestamp_ms
}
.txt"
)
...
...
@@ -140,7 +164,8 @@ for subreddit_name in subreddit_list:
"language"
:
"en"
,
"classifications"
:
[
subreddit_name
],
"properties"
:
{
"creation_date"
:
timestamp_ms
"creation_date"
:
timestamp_ms
,
"creation_date_iso"
:
timestamp_iso
}
}
...
...
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