Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/ops/spst/lrpg/opm/separate-emails.py
Дата изменения: Wed Oct 8 01:10:53 2014
Дата индексирования: Mon Apr 11 10:54:17 2016
Кодировка:
#!/usr/bin/env python
#
# 2012-06-08 ij 1.0 written to parse emails.
# 2014-10-07 ij 1.1 crashes on 2013 batch. can't key on 'From' line.
#
# how to run tool:
"""
-- select and save (export) emails to a single file
-- $LRP_WEB/opm/separate-emails.py
"""

import sys
import string
import re

fh = open(sys.argv[1])
lines = fh.readlines()
fh.close()
buf = []
first = True

fih = open('temp.temp', 'w')

n=1
for lx in lines:
#print "lx = ", string.strip(lx)
l = re.sub(r'[^\x00-\x7F]',' ', lx)
#print "l = ", l

if re.match('To: opm', string.strip(l) ):
#print "found opm match."
if not first:
#print "not first, opening file..."
fih = open(fname, 'w')
for m in buf:
fih.write("%s\n" % m)
fih.close()
buf = []


first = False

buf.append(string.rstrip(l) )

if re.match('Subject:', string.strip(l) ):
p = string.split(l)
#print "p = ", p
for x in p:
if re.match(r'[01][0-9][0123][0-9][0-9][ABCDEFGH]*', x):
lrp= x
fname = 'lrp-census-' + lrp + '.txt'
print fname