-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_comments.ps1
More file actions
39 lines (23 loc) · 1.74 KB
/
pull_comments.ps1
File metadata and controls
39 lines (23 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
param(
[Parameter(mandatory=$true)]
[string] $reddit_username
)
$total = @()
$url = "https://old.reddit.com/user/$reddit_username/.json"
$response = $(Invoke-WebRequest -URI $url).content | ConvertFrom-Json
$list = $response.data.children.data.name
$total += $response.data.children
@"
Pulling comments for user: $reddit_username
"@
do {
$x++
$last = $list[24]
$url = "https://old.reddit.com/user/$reddit_username/.json?after=$last"
$response = $(Invoke-WebRequest -URI $url).content | ConvertFrom-Json
$list = $response.data.children.data.name
"Page: $x"
$total += $response.data.children
} until ($list.count -ne 25)
#} until ($x -gt 5 -or $list.count -ne 25) # for testing
$total | convertto-json -depth 10 | out-file "./data/$reddit_username`_comments_$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss").json"