Skip to content

Commit

Permalink
[+] Backup issue #261 analysis code
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed May 16, 2024
1 parent a2abe13 commit d70baeb
Show file tree
Hide file tree
Showing 5 changed files with 577 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/2024-05-16-reddit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Issue #261 analysis

For context, see https://github.com/hykilpikonna/hyfetch/issues/261

The files in this directory are related to the automated sentiment analysis for the Reddit comments.

* `reddit.js`: JS script to crawl relevant Reddit comments.
* `reddit.json`: Crawled raw data
* `reddit_gpt.py`: Python script categorizing comment sentiment using GPT-4o
* `reddit_opinions.json`: Categorized sentiment data

These files are not really related to the functionality of hyfetch, but I'm pushing them here to
make my analysis reproducible, and preserve the data in case the reddit post is deleted.
18 changes: 18 additions & 0 deletions tools/2024-05-16-reddit/reddit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

function trimSpaces(s) {
return s.replaceAll("\n", "").replace(/\s+/g, ' ').trim();
}
const cmts = $("shreddit-comment")
const out = []
// Parse comments from html
cmts.each((i, cmt) => {
const $cmt = $(cmt)
// Author: slot="commentMeta" (use the first one)
const author = trimSpaces($cmt.find("[slot=commentMeta]").first().text())
// Content: slot="comment"
const content = trimSpaces($cmt.find("[slot=comment]").first().text())
// Upvotes: score attribute of shreddit-comment-action-row
const upvotes = parseInt($cmt.find("shreddit-comment-action-row").attr("score"))
out.push({ author, content, upvotes })
})
out
Loading

0 comments on commit d70baeb

Please sign in to comment.