murklins (murklins) wrote in pinboard,
murklins
murklins
pinboard

Renaming tags

Hey new Pinboarders, how's it going? I've been pretty busy recently getting a few fandom newsletters settled over at Pinboard and I've been finding that any accounts that relied on tag bundles to keep their hundreds of tags organized have a pretty brutal tag renaming process to go through if they want to maintain any kind of order. I settled on using prefixed tags in a couple accounts that needed them, but using the Pinboard interface to stick "pairing:" in front of every single pairing tag is slooooooooooow, especially since right now it's not so much renaming as adding a new tag and then deleting the old one.

But Pinboard has a great API, very similar to Delicious, so there's a programmatic way to do it that is faster and requires a lot less work. I used a little python script to rename all dotcoms_refresh's ~1500 tags, and it made me wonder if other people might want to take advantage of it? It's really basic and nothing special, but if you have python already installed (or feel like installing it), and are not afraid of running a script, you can save yourself some serious time. Anyone interested in getting code + instructions? Comment and I will provide! Also, if you aren't up to running a script, but your case is DIRE, let me know and, time & demand permitting, I can probably work with you one-on-one and run the script for you.

ETA: Okay, brace yourselves, these are long.

Instructions:
  1. Before you do a single thing, BACKUP YOUR PINBOARD BOOKMARKS. This script will modify tags in your account and there is no undo command if things go sour.
  2. Get python-pinboard, a pinboard python module. For the purposes of simplifying these instructions, if you are on Mac OS X, save it to your Desktop. If you are on Windows, save it to the top level of your C:\ drive. Now unzip it.
  3. Install python-pinboard:
    • Open a command window:
      Mac OS X: Applications --> Utilities --> Terminal
      Windows: Start --> Run --> type cmd.exe into the dialogue
    • Change to the python-pinboard folder you unzipped (it will have a long name like mgan59-python-pinboard-1d245a8):
      Mac OS X: Type cd ~/Desktop/mgan59-python-pinboard-1d245a8
      Windows: Type cd C:\mgan59-python-pinboard-1d245a8
    • Install the module:
      Mac OS X: Type python setup.py install
      Windows: Type python setup.py install

      If you're on Windows and get 'python' is not recognized as an internal or external command, operable program or batch file try looking at this comment thread.
  4. Download tagrename.zip and save it to your Desktop (Mac OS X) or your C:\ drive (Windows). Unzip it.
  5. In the unzipped tagrename folder, find the tags.txt file and open it in a text editor, like Notepad or TextEdit. If you know about regular expressions and have a text editor capable of using them in Find/Replace, now would be a good time to use that editor.
  6. Here's where you do all the horrid manual renaming work. Go to your pinboard page and make sure you've clicked the link to see all your tags. Copy them all and paste them into the tags.txt file. You should get one tag per line. Now beside each tag, add a space and the new tag name you want to rename it to. You want your file to be formatted such that each line has the old tag name, a space (or a tab), and then the new tag name. If there are any tags you don't want to rename, just delete them from the list.

    (FOR EXCEL USERS: read tahariel's comment on how to use Excel to set up the tags.txt file.)

    (FOR REGEX USERS: I used the Text Wrangler editor for Mac OS X and found the following regex patterns useful:
    • Find all lines with a forward slash and add a "pairing:" prefixed tag to each line. Find: (.*/.*) Replace: \1 pairing:\1
    • Find all lines with the word pairing. Find: .*pairing.*
    • Find all lines without the word pairing. Find: ^((?!pairing).)*$
    • Add a space and a prefixed copy of the tag to each line. Find: (.*) Replace: \1 prefix:\1
    I pretty much suck at regex, but with these and similar variations, I managed to do relatively little typing to get my tags.txt file ready.)
  7. Now save and close that tags.txt file and let's get ready to run the renaming script! Go back to your command window and change into the tagrename folder:
    Mac OS X: Type cd ~/Desktop/tagrename
    Windows: Type cd C:\tagrename
  8. Run the script:
    Mac OS X: Type python pinboard_tagrename.py
    Windows: Type python pinboard_tagrename.py
  9. It will prompt you for your pinboard account name, your pinboard password, and the name of the file that holds all the old and new tag names. Enter in all the necessary info:
    Pinboard account: murklins
    Pinboard password (will display as you type): 123456
    Tag names file: tags.txt
  10. Now it should start slowly renaming your tags. When it's done, it will display done!


Let me know if you hit any snags, I'll help out as best I can in the comments. Also, if the instructions seem wrong to you somehow, please speak up so I can fix them!
Subscribe

  • Auto export to webpage

    Hello, Pinboarders! I have a question - and please delete or let me know if I'm not asking in the right place. Right now, I have a fic rec site that…

  • Kink meme script

    Last December, a kink meme mod asked me if there were any tools out there to assist in getting meme prompts into Pinboard. Naturally, there are not.…

  • Export by Tag/Bulk "Copy to mine"

    Hi there. I wanted to export some of my pinboard bookmarks, but not all. Is there a way to export by tag? I also have a friend who has bookmarked…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic
  • 71 comments

  • Auto export to webpage

    Hello, Pinboarders! I have a question - and please delete or let me know if I'm not asking in the right place. Right now, I have a fic rec site that…

  • Kink meme script

    Last December, a kink meme mod asked me if there were any tools out there to assist in getting meme prompts into Pinboard. Naturally, there are not.…

  • Export by Tag/Bulk "Copy to mine"

    Hi there. I wanted to export some of my pinboard bookmarks, but not all. Is there a way to export by tag? I also have a friend who has bookmarked…