Created
September 15, 2013 00:57
-
-
Save lyoshenka/6567152 to your computer and use it in GitHub Desktop.
Merge two Pinboard tags into one, or rename a tag.
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
#!/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