示例#1
0
    def parse_cursor(self, cursor):
        i = 0
        texts = []
        contactLookup = {}
        query = cursor.execute(
            'SELECT is_madrid, madrid_handle, address, date, text, madrid_date_read, flags \
            FROM message; ')
        for row in query:
            if row[0]:
                txt = core.Text(num=row[1],
                                date=long((row[3] + 978307200) * 1000),
                                incoming=(row[5] == 0),
                                body=row[4])
            else:
                from_me = row[6] & 0x01
                txt = core.Text(num=row[2],
                                date=long(row[3] * 1000),
                                incoming=(from_me == 1),
                                body=row[4])
            if not txt.num:
                txt.num = "unknown"
                core.warning("extracted text without number. row: %s" %
                             str(row))

            lookup_num = str(txt.num)[-10:]
            if not lookup_num in contactLookup:
                contactLookup[lookup_num] = i
            txt.cid = contactLookup[lookup_num]
            texts.append(txt)
            i += 1
        return texts
示例#2
0
文件: main.py 项目: willsn0w/pyMeme
 def generate(self):
     background = cache.get_bitmap(self.path)
     width, height = background.GetSize()
     page = core.Page()
     page.add(core.Bitmap(background))
     text_width = width - self.padding * 2
     header = core.Text(
         self.header.upper(),
         text_width,
         alignment=self.header_alignment,
         border_color=(0, 0, 0),
         border_size=self.border_size,
         color=(255, 255, 255),
         font=core.font('Impact', self.header_size),
     )
     page.add(header, (width / 2, self.padding), (0.5, 0))
     footer = core.Text(
         self.footer.upper(),
         text_width,
         alignment=self.footer_alignment,
         border_color=(0, 0, 0),
         border_size=self.border_size,
         color=(255, 255, 255),
         font=core.font('Impact', self.footer_size),
     )
     page.add(footer, (width / 2, -self.padding), (0.5, 1))
     bitmap = wx.EmptyBitmap(width, height)
     dc = wx.MemoryDC(bitmap)
     page.render(dc, (width, height), (0, 0))
     return bitmap
示例#3
0
    def parse(self, file):
        """ Parse iOS 5 sqlite file to Text[] """

        conn = sqlite3.connect(file)
        c = conn.cursor()
        i = 0
        texts = []
        contactLookup = {}
        query = c.execute(
            'SELECT is_madrid, madrid_handle, address, date, text, madrid_date_read, flags FROM message;'
        )
        for row in query:
            if row[0]:
                txt = core.Text(row[1], long((row[3] + 978307200) * 1000),
                                (row[5] == 0), row[4])
            else:
                from_me = row[6] & 0x01
                txt = core.Text(row[2], long(row[3] * 1000), (from_me == 1),
                                row[4])

            lookup_num = str(txt.num)[-10:]
            if not lookup_num in contactLookup:
                contactLookup[lookup_num] = i
            txt.cid = contactLookup[lookup_num]
            texts.append(txt)

            i += 1
        return texts
示例#4
0
    def parse_file(self, file):
        inreader = unicodecsv.reader(file, encoding='utf-8')

        #gather needed column indexes from the csv file
        firstrow = inreader.next()  #skip the first line (column names)
        phNumberIndex = firstrow.index(
            "PhoneNumber") if "PhoneNumber" in firstrow else -1
        dateIndex = firstrow.index(
            "TimeRecordedUTC") if "TimeRecordedUTC" in firstrow else -1
        typeIndex = firstrow.index(
            "Incoming") if "Incoming" in firstrow else -1
        bodyIndex = firstrow.index("Text") if "Text" in firstrow else -1
        cidIndex = firstrow.index(
            "ContactID") if "ContactID" in firstrow else -1

        #check to be sure they all exist
        if (-1) in [phNumberIndex, dateIndex, typeIndex, bodyIndex, cidIndex]:
            print("CSV file missing needed columns. has: " + str(firstrow))
            quit()

        texts = []
        i = 0
        for row in inreader:
            txt = core.Text(
                row[phNumberIndex],  #number
                long(
                    float(
                        dateutil.parser.parse(
                            row[dateIndex]).strftime('%s.%f')) * 1000),  #date
                row[typeIndex] == '0',  #type
                row[bodyIndex])  #body
            texts.append(txt)
            i += 1
        file.close()
        return texts
示例#5
0
    def parse_cursor(self, cursor):

        handles = {}
        query = cursor.execute('SELECT ROWID, id, country FROM handle')
        for row in query:
            handles[row[0]] = (row[1], row[2], core.cleanNumber(row[1]))

        chats = {}  # room_name -> [members]
        #query = cursor.execute('SELECT room_name, ROWID FROM chat WHERE room_name <> "" ')
        query = cursor.execute('SELECT chat.room_name, handle.id FROM chat \
             LEFT OUTER JOIN chat_handle_join ON chat_handle_join.chat_id = chat.ROWID \
             JOIN handle ON chat_handle_join.handle_id = handle.ROWID \
             WHERE chat.room_name <> "" ')
        for row in query:
            if (not row[0] in chats): chats[row[0]] = []
            chats[row[0]].append(row[1])

        texts = []
        query = cursor.execute(
            'SELECT message.handle_id, message.date, message.is_from_me, message.text, chat.room_name \
             FROM message \
             LEFT OUTER JOIN chat_message_join ON message.ROWID = chat_message_join.message_id \
             LEFT OUTER JOIN chat ON chat_message_join.chat_id = chat.ROWID \
             ORDER BY message.ROWID ASC;')
        for row in query:
            number = handles[row[0]][0] if row[0] in handles else "unknown"
            text = core.Text(num=number,
                             date=long((row[1] + 978307200) * 1000),
                             incoming=row[2] == 0,
                             body=row[3],
                             chatroom=row[4],
                             members=(chats[row[4]] if row[4] else None))
            texts.append(text)
        return texts
示例#6
0
 def parse_cursor(self, cursor):
     texts = []
     query = cursor.execute(
         'SELECT address, date, type, body \
          FROM sms \
          ORDER BY _id ASC;')
     for row in query:
         txt = core.Text(num=row[0],date=long(row[1]),incoming=(row[2]==2),body=row[3])
         texts.append(txt)
     return texts
示例#7
0
 def parse(self, filepath):
     """ Parse XML file to Text[] """
     texts = []
     with open(filepath, 'r') as file:
         dom = xml.dom.minidom.parse(file)
         i = 0
         for sms in dom.getElementsByTagName("sms"):
             txt = core.Text( num=sms.attributes['address'].value, date=sms.attributes['date'].value,
                     incoming=(sms.attributes['type'].value==2), body=sms.attributes['body'].value)
             texts.append(txt)
         return texts
示例#8
0
 def parse(self, file):
     """ Parse XML file to Text[] """
     texts = []
     dom = xml.dom.minidom.parse(file)
     i = 0
     for sms in dom.getElementsByTagName("sms"):
         txt = core.Text(sms.attributes['address'].value,
                         sms.attributes['date'].value,
                         (sms.attributes['type'].value == 2),
                         sms.attributes['body'].value)
         texts.append(txt)
     return texts
示例#9
0
    def parse(self, file):
        """ Parse iOS 6 sqlite file to Text[] """

        conn = sqlite3.connect(file)
        c = conn.cursor()
        texts = []
        query = c.execute(
            'SELECT handle.id, message.date, message.is_from_me, message.text, message.handle_id \
             FROM message \
             INNER JOIN handle ON message.handle_id = handle.ROWID \
             ORDER BY message.ROWID ASC;')
        for row in query:
            txt = core.Text(row[0],long((row[1] + 978307200)*1000),(row[2]==1),row[3])
            texts.append(txt)
        return texts
示例#10
0
 def parse_cursor(self, cursor):
     texts = []
     query = cursor.execute('select\
         ppl.normalized_destination as num,\
         p.timestamp as date,\
         case when m.sender_id in (select _id from participants where contact_id=-1) then 2 else 1 end incoming,\
         p.text as body\
         from messages m, conversations c, parts p, participants ppl, conversation_participants cp\
         where (m.conversation_id = c._id) and (m._id = p.message_id) and (cp.conversation_id = c._id) and (cp.participant_id = ppl._id);\
         ')
     for row in query:
         txt = core.Text(num=row[0],
                         date=long(row[1]),
                         incoming=(row[2] == 2),
                         body=row[3])
         texts.append(txt)
     return texts
示例#11
0
    def parseSQL(self, file):
        """ Parse a GV sqlite file to Text[] """

        conn = sqlite3.connect(file)
        c = conn.cursor()
        texts = []
        query = c.execute(
            'SELECT TextMessageID, TimeRecordedUTC, Incoming, Text, PhoneNumber \
            FROM TextMessage \
            INNER JOIN TextConversation ON TextMessage.TextConversationID = TextConversation.TextConversationID \
            INNER JOIN Contact ON TextConversation.ContactID = Contact.ContactID \
            ORDER BY TextMessage.TextMessageID ASC')
        for row in query:
            try:
                ttime = time.mktime(
                    time.strptime(row[1], '%Y-%m-%d %H:%M:%S.%f'))
            except ValueError:
                ttime = time.mktime(time.strptime(row[1], '%Y-%m-%d %H:%M:%S'))
            txt = core.Text(row[4], long(ttime * 1000), row[2] == 0, row[3])
            texts.append(txt)
        return texts
def process_TextConversation(
        textnodes,
        onewayname):  #a list of texts, and the title used in special cases
    text_collection = TextConversation()
    text_collection.texts = []
    for i in textnodes:
        textmsg = core.Text()
        textmsg.contact = find_Contact(i)
        if text_collection.contact.test(
        ) == False:  #if we don't have a contact for this conversation yet
            if textmsg.contact.name != None:  #if contact not self
                text_collection.contact = deepcopy(
                    textmsg.contact)  #They are other participant
        textmsg.date = parse_date(
            i.find(as_xhtml('./abbr[@class="dt"]')).attrib["title"])
        #date
        textmsg.text = unescape(i.findtext(
            as_xhtml('./q')))  #Text. TO DO: html decoder
        text_collection.texts.append(deepcopy(textmsg))
        #newline
    if not text_collection.contact.test(
    ):  #Outgoing-only conversations don't contain the recipient's contact info.
        text_collection.contact.name = onewayname  #Pull fron title. No phone number, but fixed in other finction
    return text_collection
示例#13
0
                row[phNumberIndex],  #number
                long(
                    float(
                        dateutil.parser.parse(
                            row[dateIndex]).strftime('%s.%f')) * 1000),  #date
                row[typeIndex] == '0',  #type
                row[bodyIndex])  #body
            texts.append(txt)
            i += 1
        return texts

    def write(self, texts, outfile):
        writer = unicodecsv.writer(outfile,
                                   quoting=unicodecsv.QUOTE_NONNUMERIC,
                                   encoding='utf-8')
        writer.writerow(texts[0].__dict__.keys())
        writer.writerows([text.__dict__.values() for text in texts])


if __name__ == '__main__':
    import os, random, StringIO
    ENCODING_TEST_STRING = u'Δ, Й, ק, ‎ م, ๗, あ, 叶, 葉, and 말.'
    true_texts = [ core.Text("8675309", 1326497882355L, True, 'Yo, what\'s up boo? you so "cray"'), \
        core.Text("+1(555)565-6565", 1330568484000L, False, "Goodbye cruel testing."),\
        core.Text("+1(555)565-6565", random.getrandbits(43), False, ENCODING_TEST_STRING)]
    # file = open(os.path.join(os.path.dirname(__file__),'test.csv'), 'w')
    file = StringIO.StringIO()
    Tabular().write(true_texts, file)
    file.seek(0)
    print file.read().decode('utf-8')
示例#14
0
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()
FPS = 60
running = True

if __name__ == "__main__":
    panel = widgets.Panel(core.Grid((3, 7), (WINDOW_WIDTH, WINDOW_HEIGHT)),
                          None, None, (0, 0))
    panel.set_color((55, 55, 55, 255))
    midpanel = widgets.Panel(
        core.Grid((1, 1), (panel.get_cell_width(), panel.get_cell_height())),
        panel, (1, 1), None)
    midpanel.set_color((0, 0, 0, 255))
    midpanel.set_span((0, 6))
    button = widgets.TextButton(midpanel, (0, 0),
                                core.Text("Button " + str(0), 32))
    button.set_color((0, 100, 0, 255))
    button.set_border((255, 0, 0, 255), 16)

    def redraw():
        pygame.display.flip()
        screen.fill((0, 0, 0))
        panel.draw(screen)
        midpanel.draw(screen)
        button.draw(screen)


while (running):
    clock.tick(FPS)
    redraw()
    for e in pygame.event.get():
WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 728

pygame.init()
pygame.font.init
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()
FPS = 60
running = True

if __name__ == "__main__":
    panel = widgets.Panel(core.Grid((3, 20), (WINDOW_WIDTH, WINDOW_HEIGHT)),
                          None, None, (0, 0))
    panel.set_color((155, 155, 155, 255))
    texts = [
        widgets.TextLabel(panel, (1, 5), core.Text('Hello World!', 16,
                                                   core.RED), 0),
        widgets.TextLabel(panel, (1, 6), core.Text('Hello World!', 16,
                                                   core.RED), 1),
        widgets.TextLabel(panel, (1, 7), core.Text('Hello World!', 16,
                                                   core.RED), 2)
    ]

    def redraw():
        pygame.display.flip()
        screen.fill((0, 0, 0))
        panel.draw(screen)
        for x in map((lambda x: x.draw(screen)), texts):
            pass


while (running):
示例#16
0
 def asTexts(dct):
     if ('body' in dct) and ('date' in dct) and ('num' in dct):
         return core.Text(**dct)
     return dct
示例#17
0
import widgets

# Text label example.

WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 728

pygame.init()
pygame.font.init
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()
FPS = 60
running = True

if __name__ == "__main__":	
    text = widgets.TextLabel(None, None, core.Text("Hello World!", 32, core.RED))
    text.pos = [
        200,
        300
    ]
    button = widgets.RectButton(None, None)
    button.pos = [
        500,
        400,
    ]
    button.dimensions = [
        128,
        128
    ]
    button.set_color(core.GREEN)
    def redraw():
示例#18
0
                    float(
                        dateutil.parser.parse(
                            row[dateIndex]).strftime('%s.%f')) * 1000),  #date
                row[typeIndex] == '0',  #type
                row[bodyIndex])  #body
            texts.append(txt)
            i += 1
        file.close()
        return texts

    def write(self, texts, outfilepath):
        with open(outfilepath, 'w') as outfile:
            writer = unicodecsv.writer(outfile,
                                       quoting=unicodecsv.QUOTE_NONNUMERIC,
                                       encoding='utf-8')
            writer.writerow(texts[0].__dict__.keys())
            writer.writerows([text.__dict__.values() for text in texts])


if __name__ == '__main__':
    import os, random, StringIO
    ENCODING_TEST_STRING = u'Δ, Й, ק, ‎ م, ๗, あ, 叶, 葉, and 말.'
    true_texts = [ core.Text("8675309", 1326497882355, True, 'Yo, what\'s up boo? you so "cray"'), \
        core.Text("+1(555)565-6565", 1330568484000, False, "Goodbye cruel testing."),\
        core.Text("+1(555)565-6565", random.getrandbits(43), False, ENCODING_TEST_STRING)]
    # file = open(os.path.join(os.path.dirname(__file__),'test.csv'), 'w')
    file = StringIO.StringIO()
    Tabular().write(true_texts, file)
    file.seek(0)
    print(file.read().decode('utf-8'))
示例#19
0
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()
FPS = 60
running = True

if __name__ == "__main__":	
    panel = widgets.Panel(core.Grid((3, 10), (WINDOW_WIDTH, WINDOW_HEIGHT)), None, None, (0, 0))
    panel.set_color((155, 155, 155, 255))
    text = widgets.TextLabel(panel, (1, 2), core.Text(
        """
        Lorem ipsum dolor sit amet, 
        consectetur adipiscing elit,
        sed do eiusmod tempor incididunt
        ut labore et dolore magna aliqua.
        Ut enim ad minim veniam, quis
        nostrud exercitation ullamco laboris
        nisi ut aliquip ex ea commodo consequat.
            Duis aute irure dolor in
            reprehenderit in voluptate velit
            esse cillum dolore eu fugiat
            nulla pariatur. Excepteur sint
            occaecat cupidatat non proident,
            sunt in culpa qui officia deserunt
            mollit anim id est laborum.""", 13, core.BLACK)
    )
    text.set_color(core.WHITE) # This is the color of the widget, not to be confused with the color of its text.
    text.set_span((0, 5))
    text.set_border(core.BLACK, 8)
    text.set_margin(10) # Altering the margin because of the border.

    def redraw():
        pygame.display.flip()
WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 728

pygame.init()
pygame.font.init
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()
FPS = 60
running = True

if __name__ == "__main__":
    panel = widgets.Panel(core.Grid((3, 7), (WINDOW_WIDTH, WINDOW_HEIGHT)),
                          None, None, (0, 0))
    panel.set_color((100, 100, 100, 255))
    buttons = [
        widgets.TextButton(panel, (1, n), core.Text("Button " + str(n), 32))
        for n in range(7)
    ]
    [x.set_image("gfx/bg1.bmp") for x in buttons]

    def redraw():
        pygame.display.flip()
        screen.fill((0, 0, 0))
        panel.draw(screen)
        [x.draw(screen) for x in buttons]


while (running):
    clock.tick(FPS)
    redraw()
    for e in pygame.event.get():
示例#21
0
WINDOW_WIDTH = 1024
WINDOW_HEIGHT = 728

pygame.init()
pygame.font.init
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
clock = pygame.time.Clock()
FPS = 60
running = True

if __name__ == "__main__":
    panel = widgets.Panel(core.Grid((3, 20), (WINDOW_WIDTH, WINDOW_HEIGHT)),
                          None, None, (0, 0))
    panel.set_color((155, 155, 155, 255))
    text = widgets.TextLabel(panel, (1, 5),
                             core.Text("Hello World!", 32, core.RED))

    def redraw():
        pygame.display.flip()
        screen.fill((0, 0, 0))
        panel.draw(screen)
        text.draw(screen)


while (running):
    clock.tick(FPS)
    redraw()
    for e in pygame.event.get():
        if e.type == pygame.QUIT:
            sys.exit()