Beispiel #1
0
async def main(argv):
    total = 40
    if len(argv) == 2:
        total = int(argv[1])

    signal = pulsate.SignalCli()
    await signal.connect()

    config = pulsate.load_config()
    database_filename = config["database"]
    signal_db = pulsate.SignalMessageDatabase(database_filename)

    my_telephone = config["my_telephone"]

    for message in signal_db.fetch()[-total:]:
        display_prefix = ""

        if message.group_id:
            group_name = await signal.get_group_name(message.group_id)
            if group_name == "":
                group_name = "(Unnamed group)"

            group_id = codecs.encode(message.group_id, 'hex').decode('ascii')
            group_name += " %s" % group_id
        else:
            group_name = None

        if message.destination is None:
            if group_name:
                display_prefix += "%s - " % group_name

            if message.source == my_telephone:
                contact_name = "Me"
            else:
                contact_name = await signal.get_contact_name(message.source)

            if contact_name is None:
                display_prefix += "%s" % message.source
            else:
                display_prefix += "%s (%s)" % (
                    contact_name, message.source)
        else:
            destination = await signal.get_contact_name(message.destination)

            display_prefix += "Me to %s (%s)" % (
                destination, message.destination)

        if message.text:
            print("%s: %s" % (display_prefix, message.text))

        for attachment in message.attachments:
            try:
                file_type = magic.from_file(attachment, mime=True)
            except FileNotFoundError:
                file_type = "<deleted>"

            print("%s: Attachment: %s %s" %
                  (display_prefix, file_type, attachment))
Beispiel #2
0
    async def main(self):
        self.signal = pulsate.SignalCli()
        await self.signal.connect()

        database_filename = self.config["database"]
        self.signal_db = pulsate.SignalMessageDatabase(database_filename)

        for message in self.signal_db.fetch():
            await self.update(message)
Beispiel #3
0
async def main():
    config = pulsate.load_config()
    my_telephone = config["my_telephone"]

    cmd = 'signal-cli -u "%s" daemon' % my_telephone
    process = subprocess.Popen(cmd, shell=True)

    signal = pulsate.SignalCli()

    # Keep trying connect until it works
    while True:
        try:
            await signal.connect()
            break
        except dbus_next.errors.DBusError:
            continue

    config = pulsate.load_config()
    database_filename = config["database"]
    signal_db = pulsate.SignalMessageDatabase(database_filename)

    while True:
        message = await signal.receive_message()
        signal_db.add(message)

        # Display the info

        display_line = ""

        if message.group_id:
            group_name = await signal.get_group_name(message.group_id)
            if group_name == "":
                group_name = "(Unnamed group)"
        else:
            group_name = None

        if message.destination is None:
            if group_name:
                display_line += "%s - " % group_name

            contact_name = await signal.get_contact_name(message.source)
            display_line += "%s: %s" % (contact_name, message.text)
        else:
            if group_name:
                destination = group_name
            else:
                destination = await signal.get_contact_name(message.destination
                                                            )

            display_line += "Me to %s: %s" % (destination, message.text)

        print(display_line)

        if message.attachments:
            for attachment in message.attachments:
                print("  Attachment:", attachment)
Beispiel #4
0
async def main():
    signal = pulsate.SignalCli()
    await signal.connect()

    config = pulsate.load_config()
    database_filename = config["database"]
    signal_db = pulsate.SignalMessageDatabase(database_filename)

    while True:
        message = await signal.receive_message()
        signal_db.add(message)

        # Display the info

        display_line = ""

        if message.group_id:
            group_name = await signal.get_group_name(message.group_id)
            if group_name == "":
                group_name = "(Unnamed group)"
        else:
            group_name = None

        if message.destination is None:
            if group_name:
                display_line += "%s - " % group_name

            contact_name = await signal.get_contact_name(message.source)
            display_line += "%s: %s" % (contact_name, message.text)
        else:
            if group_name:
                destination = group_name
            else:
                destination = await signal.get_contact_name(message.destination
                                                            )

            display_line += "Me to %s: %s" % (destination, message.text)

        print(display_line)

        if message.attachments:
            for attachment in message.attachments:
                print("  Attachment:", attachment)
Beispiel #5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--user')
    args = parser.parse_args()

    if args.user is None:
        return -1

    choice = args.user

    config = pulsate.load_config()
    channel, is_group = pulsate.select_contact(choice, config)

    if is_group:
        print("error: no support for groups yet", file=sys.stderr)
        return -1

    database_filename = config["database"]
    signal_db = pulsate.SignalMessageDatabase(database_filename)

    for message in signal_db.fetch_by_source(channel):
        print(message.text)
Beispiel #6
0
async def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('--filter')
    parser.add_argument('--total', type=int)
    args = parser.parse_args()

    total = args.total if args.total is not None else 40

    signal = pulsate.SignalCli()
    await signal.connect()

    config = pulsate.load_config()
    database_filename = config["database"]
    signal_db = pulsate.SignalMessageDatabase(database_filename)

    my_telephone = config["my_telephone"]

    for message in signal_db.fetch()[-total:]:
        display_prefix = ""

        if message.group_id:
            group_name = await signal.get_group_name(message.group_id)
            if group_name is None:
                group_name = "(Unnamed group)"

            if args.filter is not None and group_name != args.filter:
                continue

            group_id = codecs.encode(message.group_id, 'hex').decode('ascii')
            group_name += " %s" % group_id
        else:
            group_name = None

        if message.destination is None:
            if group_name:
                display_prefix += "%s - " % group_name

            if message.source == my_telephone:
                contact_name = "Me"
            else:
                contact_name = await signal.get_contact_name(message.source)

            if args.filter is not None and contact_name != args.filter:
                continue

            if contact_name is None:
                display_prefix += "%s" % message.source
            else:
                display_prefix += "%s (%s)" % (contact_name, message.source)
        else:
            destination = await signal.get_contact_name(message.destination)

            if args.filter is not None and destination != args.filter:
                continue

            display_prefix += "Me to %s (%s)" % (destination,
                                                 message.destination)

        if message.text:
            print("%s: %s" % (display_prefix, message.text))

        for attachment in message.attachments:
            try:
                file_type = magic.from_file(attachment, mime=True)
            except FileNotFoundError:
                file_type = "<deleted>"

            print("%s: Attachment: %s %s" %
                  (display_prefix, file_type, attachment))