#import copy import os #import sys #import lxml.etree as etree #import subprocess #from datetime import datetime import docing import filing #from lxml.builder import ElementMaker from nitpo import Nitpo from emailer import Emailer from surks import Surks from xpaths import Xpaths from profile import Profile class Anpro(Nitpo): def __init__(self, do_verbose=False): """profile surveys""" super().__init__() #ns = self.const['ns'] #self.nsmap = {None: ns} #self.N = "{%s}" % self.const['ns'] #self.E = ElementMaker(nsmap=self.const['nsmap']) #self.check_conf('folders', 'profile') #self.to_print = '' self.emailer = Emailer() self.profile = Profile() self.xpaths = Xpaths() self.surks = Surks() #self.event = {} self.do_verbose = do_verbose def from_emad(self, emad, source=None, time=None): fufi = self.profile.fufi_from_emad(emad) digest = filing.md5(fufi) base = 'anpro/' + digest doc = self.profile.load(emad) doc = self.decorate(doc, source=source, time=time) root_ele = doc.getroot() if source is not None: root_ele.attrib['source'] = source if time is not None: root_ele.attrib['time'] = time # # if there are no live subscriptions quit if not self.xpaths.has_it(doc, '/n:profile/n:live/n:surk'): ## supposed to run the command line, so ok to print print('anpro sees no live surk.') return None # # take the base from the doc self.emailer.prepare(doc, empro='anpro', base=base) def from_doc(self, doc, source=None, time=None): doc = self.decorate(doc, source=source, time=time) # # if there are no live subscriptions quit if not self.xpaths.has_it(doc, '/n:profile/n:live/n:surk'): if self.is_dev: print('anpro sees no live surk.') return None # # take the base from the doc digest = filing.digest(docing.show(doc)) base = 'anpro/' + digest self.emailer.prepare(doc, empro='anpro', base=base) def decorate(self, doc, source=None, time=None): root_ele = doc.getroot() if source is not None: root_ele.attrib['source'] = source if time is not None: root_ele.attrib['time'] = time else: root_ele.attrib['time'] = self.now() root_ele.attrib['dalacha'] = self.surks.get_dalacha(doc) return doc