Esempio n. 1
0
 def _processAdiumLog(self, db, path, id):
     
     file = open(path, 'r')
     line = file.read()
     file.close()
     
     # Line breaks confuse things later on.
     line = line.replace('<br />', '&lt;br /&gt;')
     
     writeFile = open(path + '_temp', 'w')
     writeFile.write(line)
     writeFile.close()
     
     xml = etree.parse(path + '_temp')
     root = xml.getroot()
     
     username = ''
     service = ''
     for name, value in root.items():            
         if name == 'account':
             username = value
         if name == 'service':
             service = value
     
     accountId, ourContactId = account.createIMAccount(db, service, username)
     
     storedConversation = False
     storedContacts = {}
     
     for child in root.getchildren():
         if child.tag.endswith('message'):
         
             alias = None
             if 'alias' in child.attrib:
                 alias = child.attrib['alias']
             address = child.attrib['sender']
             
             if address not in storedContacts:
                 contactId = contact.addEmptyContact(db, 'IM', address, alias)
                 if address.find('@') > 0:   # Crude test for email
                     contactId = contact.addAddressToExistingContact(db, contactId, 'email', address, alias)
                 
                 storedContacts[address] = contactId
             else:
                 contactId = storedContacts[address]
             
             sentTime = datetime(*time.strptime(child.attrib['time'][:19], '%Y-%m-%dT%H:%M:%S')[0:6])
             
             wrapper = child.getchildren()[0]
             node = wrapper.getchildren()[0]
             
             if node.text:
                 text = node.text.replace('&lt;br /&gt;', '\n')
 
                 if not storedConversation:
                     messageId = message.store(db, accountId, sentTime, ourContactId, text + u'...', [ourContactId], 'IM')
                     imConversation.store(db, messageId, id)
                     storedConversation = True
                 
                 if contactId != ourContactId:
                     message.addRecipient(db, messageId, contactId)
                 
                 imConversation.addEntry(db, messageId, sentTime, contactId, text)
     
     os.remove(path + '_temp')
Esempio n. 2
0
 def _processMsnLog(self, db, path, id):
     
     file = open(path, 'r')
     line = file.read()
     
     print id
     # Make valid XML
     line = line.replace('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">', '')
     line = line.replace('<br>', '')
     line = line.replace('&nbsp;', '')
     
     writeFile = open(path + '_temp', 'w')
     writeFile.write(line)
     writeFile.close()
             
     xml = etree.parse(path + '_temp')
     root = xml.getroot()
     body = root.getchildren()[1]
     
     paragraphs = body.getchildren()
     
     firstLine = paragraphs[0].text
     to = firstLine[4:firstLine.find('Start Time')]
     start = firstLine[firstLine.find('Start Time: ') + len('Start Time: '):]
     start = start[:start.find(';')]
     
     substring = id[id.rfind('Messenger ') + len('Messenger '): ]
     date = substring[ : 10]
     
     participant = substring[1: substring.rfind('.htm')]
     
     def findAllAliases(paragraphs):
         aliases = []
         for paragraph in paragraphs:
             if paragraph.text and paragraph.text.find(' says: (') != -1:
                 alias = paragraph.text[: paragraph.text.find(' says: (')]
                 if not alias in aliases:
                     aliases.append(alias)
         return aliases
     
     aliases = findAllAliases(paragraphs)
     
     self.answer = None
     
     if len(aliases) > 2:
         question = 'An MSN log is ambiguous about which of the following aliases is you,\nand which is '
         question += to + '.\nPlease select all the aliases that are you.'
     else:
         question = 'An MSN log is ambiguous about which of the following aliases is you,\nand which is '
         question += to + '.\nPlease click on the alias that is you.'
     
     
     self.questionAsker(aliases, 'Interpreting an IM Log', question, self.receiveAnswer, len(aliases) > 2)
     
     while not self.answer and not self.needToStop:
         time.sleep(1)
     
     if type(self.answer) != type([]):
         self.answer = [self.answer]
     ourAliases = self.answer
     
     theirAlias = [alias for alias in aliases if alias not in self.answer][0]
     
     accountId, ourContactId = account.createIMAccount(db, 'MSN', 'Unknown')
     theirContactId = contact.addEmptyContact(db, 'IM', to, theirAlias)
     
     messageId = None
     
     i = 1
     while i < len(paragraphs):
         line1 = paragraphs[i].text
         if not line1 or line1.find(' says: (') == -1:
             i+= 1  # Skip over another "To... Start Time..." line if the window was shut
         else:
             alias = line1[: line1.find(' says: (')]
             timeReceived = line1[line1.rfind('(') + 1: line1.rfind(')')]
             timeReceived = datetime(*time.strptime(date + ' ' + timeReceived, '%d.%m.%Y %H:%M:%S')[0:6])
             
             i += 1
             text = paragraphs[i].text
             i += 1
             
             if text:
                 if not messageId:
                     messageId = message.store(db, accountId, timeReceived, ourContactId, text + u'...', [ourContactId, theirContactId], 'IM')
                     imConversation.store(db, messageId, id)
                 
                 if alias in ourAliases:
                     contactId = ourContactId
                 else:
                     contactId = theirContactId
                 
                 imConversation.addEntry(db, messageId, timeReceived, contactId, text)
     
     os.remove(path + '_temp')