Sorry: this part I had posted already!

This is the second part:

---

import os
import re

##############################################
# remove OSX .DS_Store files
##############################################

for root, dirs, files in os.walk('./'):
    if '.DS_Store' in files:
        os.remove(os.path.join(root, '.DS_Store'))

##############################################
# create a temporary file
# for the directory list
##############################################

f = open('myfile_01.tmp', 'w')

for root, dirs, files in os.walk('./'):
 for name in files:
File_Path = os.path.join(root, name)
 s = File_Path + '"/>\r'
f.write(s)

f.close()

##############################################
# remove and replace text
# copy result to a new file
##############################################

f1 = open('myfile_01.tmp', 'r')
f2 = open('myfile_02.tmp', 'w')
for line in f1:
    f2.write(line.replace('./', '    <item id="<##-ID-##>" href="'))
f1.close()
f2.close()

##############################################
# Add proper mime-types
# The registry is at http://www.iana.org/assignments/media-types/
##############################################

def replace_words(text, My_Dictionary):
    rc = re.compile('|'.join(map(re.escape, My_Dictionary)))
    def translate(match):
        return My_Dictionary[match.group(0)]
    return rc.sub(translate, text)

fin = open('myfile_02.tmp', 'r')
str2 = fin.read()
fin.close()
 
My_Dictionary = {
# text_files
'.html"': '.html" media-type="application/xhtml+xml"',
'.xhtml"': '.xhtml" media-type="application/xhtml+xml"',
'.xml"': '.xml" media-type="text/xml"',
# css files
'.css"': '.css" media-type="text/css"',
# image files
'.gif"': '.gif" media-type="image/gif"',
'.jpg"': '.jpg" media-type="image/jpeg"',
'.jpeg"': '.jpeg" media-type="image/jpeg"',
'.png"': '.png" media-type="image/png"',
'.svg"': '.svg" media-type="image/svg+xml"',
# font files: ttf is not officially supported: woff is!
'.otf"': '.otf" media-type="application/x-font-otf"',
'.woff"': '.ttf" media-type="application/x-font-woff"',
'.ttf"': '.ttf" media-type="application/x-font-ttf"',
# Javascript
'.js"': '.js" media-type="application/javascript"',
# html5 audio and video
'.mp4"': '.mp4" media-type="audio/mp4"',
'.mp3"': '.mp3" media-type="audio/mpeg"',
'.m4v"': '.m4v" media-type="video/mpeg4"',
'.webm"': '.webm" media-type="video/webm"',
'.ogg"': '.ogg" media-type="audio/ogg"'
}
 
# call the function and get the changed text
str3 = replace_words(str2, My_Dictionary)
 
# write changed text back out
fout = open('myfile_03.tmp', 'w')
fout.write(str3)
fout.close()

# append the text from the third temp_file to .xml

fin2 = open('myfile_03.tmp', 'r')
str4 = fin2.read()
fin2.close()

fout2 = open('test.xml', 'a')
fout2.write(str4)
fout2.close()

##############################################
# remove the temporary Files
##############################################

filelist = [ f for f in os.listdir('./') if f.endswith('.tmp') ]
for f in filelist:
    os.remove(f)

---

-- 
-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, 
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to