Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
Created September 15, 2013 00:57
Show Gist options
  • Save lyoshenka/6567152 to your computer and use it in GitHub Desktop.
Save lyoshenka/6567152 to your computer and use it in GitHub Desktop.
Merge two Pinboard tags into one, or rename a tag.
#!/usr/bin/env php
<?php
if (!isset($argv[2]))
{
echo "${argv[0]} FROM TO\n";
exit(1);
}
include 'pinboard-api.php'; // https://github.com/kijin/pinboard-api
$pinboard = new PinboardAPI('lyoshenka', 'password');
echo "From ${argv[1]} to ${argv[2]}\n";
$all = $pinboard->get_all(null,null,array($argv[1]));
foreach ($all as $bookmark)
{
echo $bookmark->url . "\n";
echo implode(' ',$bookmark->tags) . " => ";
$bookmark->tags = preg_replace('/(^| )'.preg_quote($argv[1],'/').'( |$)/', '$1'.$argv[2].'$2', implode(' ', $bookmark->tags));
echo $bookmark->tags . "\n";
$bookmark->save();
sleep(3); // honor API rate limit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment