-
Notifications
You must be signed in to change notification settings - Fork 17
openmeta
psidnell edited this page Apr 13, 2013
·
6 revisions
I use openmeta in an autotag command to tag my generated files automatically with a Hazel rule.
You'll need to adjust these for your personal needs:
autotag
#!/bin/bash
set -e
for FPATH in "$*"; do
echo "$FPATH"
DIR=`dirname "$FPATH"`
FILE=`basename "$FPATH"`
TAGS=`~/bin/tagscan "$FPATH"`
cd "$DIR"
~/bin/openmeta -s -p ./"$FILE"
~/bin/openmeta -a $TAGS -p ./"$FILE"
done
tagscan
#!/bin/bash
python ~/bin/tagscan.py "$*"
tagscan.py
import sys
import codecs
import re
'''
These should get spotted:
#AAA
#BBB
#CCC.#DDD,#EEE(#FFF)#GGG:#HHH;#III #JJJ
'''
if __name__ == "__main__":
if len (sys.argv) != 2:
print 'single file argument expected'
sys.exit()
fname = sys.argv[1]
stream = codecs.open (fname, 'r', "utf-8")
tags = set ()
fname_tag = re.sub(".*\/", '', fname)
fname_tag = re.sub("\..*", '', fname_tag)
fname_tag = re.sub(" ", '', fname_tag)
tags.add ('#' + fname_tag)
for line in stream.readlines():
words = re.split('[ \t\r\n,\.:;\(\)]', line)
for word in words:
if re.match('^#[a-zA-Z0-9]', word) != None:
tags.add(word)
elif re.match('^[A-Z]+-[0-9]+', word):
tags.add ('#' + word)
stream.close()
tag_list = sorted(list(tags))
for tag in tag_list:
print tag,