# -*- coding: utf-8 -*- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #INTRODUCTION ''' FILE: The SMS Directory in my IDE DATE: 2017-11-06 DEAD: 2021-02-24 (c) Copyright Brett Paufler I Back-Up my SMS Text Messages using [A Utility]. The format that [Utility] Outputs is not to my liking. I wanted to improve on it. I did not get very far. The main hang-ups were: utf encoding emoji encoding image retrieval I am not using the Text Messages, anyhow. So, I abandoned this project. THERE IS NO REASON TO BELIEVE ANY OF THIS WORKS. Originally, the file names for this were: /sms images [GPS Utility] sms workspace All four files are contained within this one. I will divide each by a sting of '# # # #...' ''' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #sms ''' Created on Nov 6, 2017 @author: Brett Paufler Copyright Brett Paufler Stitch together those sms And output as html #Do same thing for images Time Images Who From EMOJI are DEAD PROBABLY NOT WORTH USING ETREE ''' import xml.etree.ElementTree as ET from os import listdir from os.path import join as join_path #import sys, locale class SMS_ALL(object): '''As all this code is total Dead Wood I shall not try to comment after the fact.''' #@classmethod def sms_files_list(self): dir_in = 'input' sms_files = listdir(dir_in) sms_files = [f for f in sms_files if 'sms' in f] sms_files = [join_path(dir_in, f) for f in sms_files] return sms_files #NOT COMPLETE IN HOLDING PATTERN #@classmethod def output_all(self): with open('output/text.txt', 'w', encoding='utf-8') as output_file: for message in self.sms_message_list: output_file.write(message.to_utf_string()) output_file.write('/n') def __init__(self): self.sms_files = self.sms_files_list() self.sms_message_list = [] def sms_file_open(self, sms_file_name): with open( sms_file_name, 'r', encoding='utf-8', #encoding='ascii', errors='ignore') as sms: #print(sms) sms = sms.read() sms = sms.split('\n') sms = sms[:21] for s in sms: print(s) #sms = sms.decode( # encoding='utf-8', # errors='namereplace' # ) #print(sms) # ) #root = ET.parse(sms) #print(sms) #root = ET.ElementTree(ET.fromstring(sms)) #print(root) root = ET.parse(sms_file_name) print(sms_file_name) return root def process_all(self): for sms_file in self.sms_files: print(sms_file) tree = self.sms_file_open(sms_file) #try: # tree = self.sms_file_open(sms_file, 'utf-8') #except: # tree = self.sms_file_open(sms_file) root = tree.getroot() for child in root: self.sms_message_list.append( SMS_MESSAGE(child)) class SMS_MESSAGE(object): def __init__(self, message): #print(message[0]) #body = child.attrib['body'] print(message.attrib['body']) body = message.attrib.get('body', False) self.body = body #body = message.attrib.getattr('body', False) print(body) if body: #self.body = True self.body_utf_ignore = str( body.encode( encoding='utf-8', errors='ignore')) self.body_utf_namereplace = str( body.encode( encoding='utf-8', errors='namereplace')) self.body_ascii_ignore = str( body.encode( encoding='ascii', errors='ignore')) self.body_ascii_namereplace = str( body.encode( encoding='ascii', errors='namereplace')) #else: # self.body = False #print(self.body) def to_utf_string(self): utf_text = '' if self.body: utf_text += '%s\n%s\n%s\n%s\n%s\n' % ( self.body, self.body_ascii_ignore, self.body_ascii_namereplace, self.body_utf_ignore, self.body_utf_namereplace) print(utf_text) return utf_text def repl(self): return self.to_string().encode( encoding='ascii', errors='ignore') if __name__ == '__main__': sms_all = SMS_ALL() sms_all.process_all() sms_all.output_all() #test.write(body) #test.write('\n') #test.write(body_a) #test.write('\n') #test.write(body_8) #test.write('\n') ''' Helpful, yes? ''' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #images ''' Created on Nov 22, 2017 @author: Brett Paufler Copyright Brett Paufler Pull images, just move on ''' from os import listdir from os.path import join as path_join import base64 all_files = [path_join('input', f) for f in listdir('input')] for file_path in all_files : #print(file_path) with open( file_path, encoding='utf-8', errors='ignore') as f: text = f.read() items = text.split('\n') items = [i.strip() for i in items] bad_line_starts = ['', '~', '', '', '