Created
September 13, 2024 07:08
-
-
Save PerryRylance/0f58c600c6f2dabc58245f1c35183bcd to your computer and use it in GitHub Desktop.
Download Slack emojis
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 | |
if($argc < 2) | |
{ | |
echo PHP_EOL . "\033[44m Instructions \033[0m" . PHP_EOL; | |
?> | |
1. Head to https://your-workspace.slack.com/customize/emoji | |
2. Open developer tools network parse_ini_file | |
3. Find <?php echo "\033[34m"; ?>emojiAdmin.list<?php echo "\033[0m"; ?>, save in this directory | |
4. Run <?php echo "\033[34m"; ?>php download.php emojis.json<?php echo "\033[0m"; ?> replacing with your JSON filename | |
5. ? | |
6. Profit! | |
<?php | |
exit(1); | |
} | |
function error(string $message) | |
{ | |
die("\033[41m{$message}\033[0m" . PHP_EOL); | |
} | |
$jsonFile = $argv[1]; | |
if(!file_exists($jsonFile)) | |
error("File not found $jsonFile"); | |
// Read and decode the JSON file | |
$jsonData = json_decode(file_get_contents($jsonFile), true); | |
if($jsonData === false) | |
error("Failed to read $jsonFile"); | |
if (!isset($jsonData['emoji']) || !is_array($jsonData['emoji'])) | |
error("Unexpected format in $jsonFile"); | |
// Loop through each element in the emoji array | |
foreach ($jsonData['emoji'] as $emoji) { | |
// Extract 'name' and 'url' properties | |
$name = $emoji['name']; | |
$url = $emoji['url']; | |
// Extract the file extension from the URL (e.g. .png, .jpg) | |
$extension = pathinfo($url, PATHINFO_EXTENSION); | |
// Create the filename by combining the name and extension | |
$filename = $name . '.' . $extension; | |
// Download the file and save it locally | |
file_put_contents($filename, file_get_contents($url)); | |
echo "Downloaded: $filename" . PHP_EOL; | |
} | |
echo "\033[42mDone!\033[0m" . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment