# import os import docing import filing 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__() 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 out = self.emailer.prepare(doc, empro='anpro', base=base) return out 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'): bugfi = open('/tmp/he', 'w') bugfi.write('none') bugfi.close() 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 bugfi = open('/tmp/he', 'w') bugfi.write('here') bugfi.close() out = self.emailer.prepare(doc, empro='anpro', base=base) return out 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