Be more descriptive with removed comments

This commit is contained in:
Christopher Gurnee 2021-10-23 12:58:06 -04:00
parent af95d9c452
commit d9c46d00e7
3 changed files with 31 additions and 3 deletions

View file

@ -1,6 +1,6 @@
const chunkSize = 100;
const postURL = 'https://api.pushshift.io/reddit/submission/search/?ids='
const commentURL = `https://api.pushshift.io/reddit/comment/search/?size=${chunkSize}&sort=asc&fields=author,body,created_utc,id,link_id,parent_id,score,subreddit&q=*&link_id=`
const commentURL = `https://api.pushshift.io/reddit/comment/search/?size=${chunkSize}&sort=asc&fields=author,body,created_utc,id,link_id,parent_id,retrieved_on,retrieved_utc,score,subreddit&q=*&link_id=`
const sleep = ms =>
new Promise(slept => setTimeout(slept, ms))

View file

@ -1,6 +1,6 @@
import React from 'react'
import { Link } from 'react-router-dom'
import { prettyScore, prettyDate, parse, isRemoved } from '../../utils'
import { prettyScore, prettyDate, prettyTimeDiff, parse, isRemoved } from '../../utils'
const Comment = (props) => {
let commentStyle = 'comment '
@ -13,7 +13,26 @@ const Comment = (props) => {
commentStyle += props.depth % 2 === 0 ? 'comment-even' : 'comment-odd'
}
const innerHTML = (isRemoved(props.body) && props.removed) ? '<p>[removed too quickly to be archived]</p>' : parse(props.body)
let innerHTML;
if (isRemoved(props.body) && props.removed) {
if (!props.hasOwnProperty('retrieved_utc') && !props.hasOwnProperty('retrieved_on') || !props.hasOwnProperty('created_utc')) {
innerHTML = '<p>[removed too quickly to be archived]</p>'
} else if (props.created_utc < 1627776000) { // Aug 1 2021
const retrieved = props.hasOwnProperty('retrieved_utc') ? props.retrieved_utc : props.retrieved_on;
innerHTML = '<p>[removed within ${prettyTimeDiff(retrieved - props.created_utc)}]</p>'
}
// After around Aug 1 2021, Pushshift began updating comments from Reddit after around
// 24-48 hours, including removing(?) comments that were removed from Reddit. The presence
// of either retrieved_utc or retrieved_on can currently be used to test for this behaviour.
else if (props.hasOwnProperty('retrieved_utc')) {
innerHTML = `<p>[removed within ${prettyTimeDiff(props.retrieved_utc - props.created_utc)}]</p>`
} else {
innerHTML = `<p>[either removed too quickly, or <a href='https://www.reddit.com/r/pushshift/comments/pgzdav/the_api_now_appears_to_rewrite_nearly_all/'>removed(?) from archive</a> after ${prettyTimeDiff(props.retrieved_on - props.created_utc)}]</p>`
}
} else {
innerHTML = parse(props.body)
}
const permalink = `/r/${props.subreddit}/comments/${props.link_id}/_/${props.id}/`
return (

View file

@ -50,6 +50,15 @@ export const prettyDate = createdUTC => {
return `${Math.floor(dayDiff / 365)} years ago`
}
// Time difference in seconds to text, rounded up (e.g. x seconds/minutes/hours)
export const prettyTimeDiff = secondDiff => {
if (secondDiff < 2) return `1 second`
if (secondDiff < 120) return `${secondDiff} seconds`
if (secondDiff < 7200) return `${Math.ceil(secondDiff / 60)} minutes`
if (secondDiff < 172800) return `${Math.ceil(secondDiff / 3600)} hours`
return `${Math.ceil(secondDiff / 86400)} days`
}
// Reddit format for scores, e.g. 12000 => 12k
export const prettyScore = score => {
if (score >= 100000) {