from xml.etree.ElementTree import fromstring, tostring
import mcoll
from config import config
import os
import glob
import sys
import traceback
dir = config.get('dir', 'entry')
c = mcoll.Collection(dir)
SRC = "/home/jcgregorio/web/bitworking.org/data/"
#for filename in [os.path.join(SRC, name) for name in os.listdir(SRC) if not name.count("-")]:
# f = file(filename, "r")
# e = fromstring(f.read())
# f.close()
#
# d = {}
# summary = e.find(u"{http://www.purl.org/RESTLog/}excerpt")
# if summary != None:
# d['summary'] = summary.text
# desc = e.find("description")
# d['content'] = desc.text
# published = e.find("{http://purl.org/dc/elements/1.1/}date")
# d['published'] = d['updated'] = published.text.rsplit("-", 1)[0]
# title = e.find("title")
# d['title'] = title.text
# d['slug'] = u''
# id = os.path.basename(filename)
#
# c._put(id, d)
# member = c.get(id)
# content = member['content'].encode("utf-8")
# summary = member['summary'].encode("utf-8")
# s = "
" % (summary, content)
# try:
# print id
# fromstring(s)
# except Exception, e:
# print s
# print e
# sys.exit(1)
#
comments_dir = config.get('dir', 'comments')
for filename in [os.path.join(SRC, name) for name in os.listdir(SRC) if name.count("-")]:
f = file(filename, "r")
e = fromstring(f.read())
f.close()
(entry_id, comment_id) = os.path.basename(filename).rsplit('-', 1)
c = mcoll.Collection(os.path.join(comments_dir, entry_id))
d = {}
author = e.find(u"{http://purl.org/dc/elements/1.1/}creator")
if author != None:
d['author'] = author.text
summary = e.find(u"{http://www.purl.org/RESTLog/}excerpt")
if summary != None:
d['summary'] = summary.text
desc = e.find("description")
d['content'] = desc.text
published = e.find("{http://purl.org/dc/elements/1.1/}date")
d['published'] = d['updated'] = published.text.rsplit("-", 1)[0]
title = e.find("title")
d['title'] = title.text
d['slug'] = u''
c._put(comment_id, d)
member = c.get(comment_id)
content = member['content'].encode("utf-8")
summary = member['summary'].encode("utf-8")
s = " " % (summary, content)
try:
print entry_id, comment_id
fromstring(s)
except Exception, e:
print s
print e
sys.exit(1)
c.reindex()