def processLine(line):
titlep=re.compile('^# (\\w+.+$)', re.LOCALE) #group 1
quotep1=re.compile('^\\t> (.+$)', re.LOCALE) #group 1
quotep2=re.compile('^\\t (.+$)', re.LOCALE) #group 1
notep1=re.compile('^\\t- (.+$)', re.LOCALE) #group 1
notep2=re.compile('^\\t (.+$)', re.LOCALE) #group 1
citep=re.compile('^\\t\\t- (@\\w+)') #group1
tagsp=re.compile('^\\t\\t(- Tags: | {8})(.+$)') #group2
ctimep=re.compile('^\\t\\t- Ctime: (.+$)') #group1
patterns={'title': [titlep,1],\
'quote1': [quotep1,1],\
'quote2': [quotep2,1],\
'note1': [notep1,1],\
'note2': [notep2,1],\
'cite': [citep,1],\
'tags': [tagsp,2],\
'ctime': [ctimep,1]\
}
for kk,vv in patterns.items():
m=vv[0].match(line)
if m:
return kk,m.group(vv[1]).encode('utf8')
return None,''
#------------Organize by tags and save------------
评论列表
文章目录