Last active
December 31, 2016 16:54
-
-
Save Vusys/a8617f39b6460855f5af2431e494b705 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user = "xxxx"; | |
$hash = "xxxx"; | |
$url = "https://www.reddit.com/r/wow/api/flairlist.json"; | |
$next = null; | |
$fp = fopen('./flair_list.csv', 'w'); | |
$has_next = true; | |
$loop = 0; | |
while ($has_next == true) { | |
$loop++; | |
$query_args = [ | |
'feed' => $hash, | |
'user' => $user, | |
'limit' => 1000, | |
]; | |
if (!is_null($next)) { | |
$query_args['after'] = $next; | |
} | |
$query = $url . '?' . http_build_query($query_args); | |
$json = file_get_contents($query); | |
$json = json_decode($json, true); | |
$subreddit_users = $json['users']; | |
foreach ($subreddit_users as $subreddit_user) { | |
fputcsv($fp, $subreddit_user); | |
} | |
if (isset($json['next'])) { | |
$next = $json['next']; | |
} else { | |
print "done!" . "\n"; | |
$has_next = false; | |
} | |
print "Downloaded {$loop} pages of users" . "\n"; | |
sleep(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment