Created
July 1, 2024 14:57
-
-
Save garvinhicking/7cd858ec0f9a20e57f16169f941e03e3 to your computer and use it in GitHub Desktop.
Pleroma rejection filter
This file contains 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 | |
$stdin = file_get_contents('php://stdin'); | |
$json = json_decode($stdin, true, JSON_OBJECT_AS_ARRAY | JSON_THROW_ON_ERROR); | |
if ($json['group'] !== ':pleroma' || $json['key'] !== ':mrf_simple') { | |
echo "Only :pleroma & :mrf_simple JSON supported. Stop feeding me microplastics.\n"; | |
exit(1); | |
} | |
$count = 0; | |
echo '"Site";"Reason"' . "\n"; | |
foreach ($json['value'] as $json_struct) { | |
if (($json_struct['tuple'][0] ?? '') === ':reject') { | |
foreach ($json_struct['tuple'][1] as $rejects) { | |
$count++; | |
echo '"' . $rejects['tuple'][0] . '";"' . str_replace('"', '""', $rejects['tuple'][1]) . '"' . "\n"; | |
} | |
} | |
} | |
echo '"Summary";"' . $count . ' rejections"' . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
cat mrf_simple.json | php parse-json.php > mrf_simple.csv