art, photography, writing, mixed media, love, transmissions, the universe, new earth


a log by aeryn

scoredashify script


A python slugify script I found and modified to create url slugs according to my own preference.

I don't understand python or regex very well, but it converts spaces to underscores, leaves alpha-numeric characters alone, and everything else becomes a dash.

I've made it into a service on my Mac so I can highlight text, run the service and paste the scoredashified text.

I wonder if I can use this script on my iPad. I have Editorial and Workflow apps, both run scripts I think.

# Based on Django's slugify text utility
# Use Automator's Run Shell Script action
# Set Shell to: /usr/bin/python;
# Set Pass input to: to stdin
# Add a keyboard shorcut (ctrl+alt+cmd+d)

import sys
import re
import unicodedata

slug_character = '_'

for value in sys.stdin:
    value = unicodedata.normalize('NFKD', value.decode('UTF-8')).encode('ascii', 'ignore').decode('ascii')
    value = re.sub('[^\w\s-]', '-', value).strip()
    value = re.sub('[\s]+', slug_character, value)
    print value,