def _datetime_str(self, v): _dt=bptime.BPTime(v) return _dt.date_str()+' '+_dt.time_str() def _priority_str(self, v): return sms.SMSEntry._priority_name.get(v, '') _csv_template=( ('Date', 'datetime', _datetime_str), ('From', '_from', None), ('To', '_to', None), ('Subj', 'subject', None), ('Text', 'text', None), ('Priority', 'priority', _priority_str), ('Read', 'read', _yesno_str), ('Locked', 'locked', _yesno_str), ('Callback', 'callback', None), ('Folder', 'folder', None)) def _export_csv(self, fp, sms): fp.write(','.join(['"'+e[0]+'"' for e in self._csv_template])+'\n') _keys=sms.keys() _keys.sort() for k in _keys: try: e=sms[k] _l=[] for _c in self._csv_template: if _c[2] is None: _s=str(getattr(e, _c[1], '')) else: _s=_c[2](self, getattr(e, _c[1], None)) _l.append('"'+_s.replace('"', '')+'"') fp.write(','.join(_l)+'\n') except: if __debug__: raise
def _export_mbox(self, fp, sms): # export SMS data to mbox format _email_generator=Generator(fp, True) _lfs='\n\n' _keys=sms.keys() _keys.sort() for k in _keys: e=sms[k] try: _msg=MIMEText(e.text) _msg['From']=e._from or 'self' _msg['To']=e._to or 'self' _msg['Subject']=e.subject if e.datetime: _msg['Date']=formatdate(bptime.BPTime(e.datetime).mktime(), True) _email_generator.flatten(_msg, True) _email_generator.write(_lfs) except: if __debug__: raise
def _export_csv(self, fp, sms): # export SMS data to CSV format # print out the header fp.write(','.join(['"'+e[0]+'"' for e in self._csv_template])+'\n') # and the entries _keys=sms.keys() _keys.sort() for k in _keys: try: e=sms[k] _l=[] for _c in self._csv_template: if _c[2] is None: _s=str(getattr(e, _c[1], '')) else: _s=_c[2](self, getattr(e, _c[1], None)) _l.append('"'+_s.replace('"', '')+'"') fp.write(','.join(_l)+'\n') except: if __debug__: raise
def _export_mbox(self, fp, sms): _email_generator=Generator(fp, True) _lfs='\n\n' _keys=sms.keys() _keys.sort() for k in _keys: e=sms[k] try: _msg=MIMEText(e.text) _msg['From']=e._from or 'self' _msg['To']=e._to or 'self' _msg['Subject']=e.subject _msg['Date']=formatdate(bptime.BPTime(e.datetime).mktime(), True) _email_generator.flatten(_msg, True) _email_generator.write(_lfs) except: if __debug__: raise def _yesno_str(self, v): if v: return 'Yes' return 'No' def _datetime_str(self, v): _dt=bptime.BPTime(v) return _dt.date_str()+' '+_dt.time_str() def _priority_str(self, v): return sms.SMSEntry._priority_name.get(v, '') _csv_template=( ('Date', 'datetime', _datetime_str), ('From', '_from', None), ('To', '_to', None), ('Subj', 'subject', None), ('Text', 'text', None), ('Priority', 'priority', _priority_str), ('Read', 'read', _yesno_str), ('Locked', 'locked', _yesno_str), ('Callback', 'callback', None), ('Folder', 'folder', None)) def _export_csv(self, fp, sms): fp.write(','.join(['"'+e[0]+'"' for e in self._csv_template])+'\n') _keys=sms.keys() _keys.sort() for k in _keys: try: e=sms[k] _l=[] for _c in self._csv_template: if _c[2] is None: _s=str(getattr(e, _c[1], '')) else: _s=_c[2](self, getattr(e, _c[1], None)) _l.append('"'+_s.replace('"', '')+'"') fp.write(','.join(_l)+'\n') except: if __debug__: raise