Skip to content

Instantly share code, notes, and snippets.

@garvinhicking
Created July 1, 2024 14:57
Show Gist options
  • Save garvinhicking/7cd858ec0f9a20e57f16169f941e03e3 to your computer and use it in GitHub Desktop.
Save garvinhicking/7cd858ec0f9a20e57f16169f941e03e3 to your computer and use it in GitHub Desktop.
Pleroma rejection filter
<?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";
@garvinhicking
Copy link
Author

Usage:

cat mrf_simple.json | php parse-json.php > mrf_simple.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment