示例#1
0
class MessageManager:
    def __init__(self, username):
        self.message = Message()
        self.username = username

    def show_inbox(self):
        messages = self.message.read_messages(self.username)
        messages_view = SelectionMenu(messages, "Inbox")
        messages_view.show()

    def show_send(self):
        receiver = input("Send to: ")
        text = input("Enter message text: ")
        self.message.send_message(text, self.username, receiver)

    def show_statuses(self):
        statuses_display = statuses.copy()
        for i in range(len(statuses)):
            count = self.message.count_messages_in_status(
                self.username, statuses[i])
            statuses_display[i] += f" | count: {count}"

        statuses_display.append("Refresh")

        statuses_view = SelectionMenu(statuses_display, "Messages in statuses")
        statuses_view.show()

        if statuses_view.selected_option == 6:  # Refresh
            self.show_statuses()
示例#2
0
def publish_message(user):
    recipient = random.choice(usernames)
    message = Message(user.username, recipient)
    tags_quantity = random.randint(0, len(tags) // 2)
    msg_tags = '' if tags_quantity == 0 else ','.join(set(random.choice(tags) for _ in range(tags_quantity)))
    message.set_data('{0} -> {1}: {2}'.format(message.sender, message.recipients, message.msg_id), msg_tags)
    print('User %s sending new message to %s' % (message.sender, message.recipients))
    ChatController.create_message(message)
    ChatController.publish_message(message)
示例#3
0
def send_messages(count_users: int):
    user_prefix = "user_id"
    client_controller = Client()
    message_controller = Message()
    for idx in range(count_users):
        users.append(user_prefix + str(idx))
        client_controller.register(users[idx])
        client_controller.login(users[idx])
    i = 0
    while True:
        from_username = user_prefix + str(randrange(len(users)))
        to_username = from_username
        while to_username != from_username:
            to_username = user_prefix + str(randrange(len(users)))
        message = "test message, id:" + str(i)
        i += 1
        message_controller.send_message(message, from_username, to_username)
        sleep(2)
示例#4
0
 def launchCampaign(self, campaign_id):
     conn = yield connection
     campaign = yield r.table("Campaign").get(campaign_id).run(conn)
     target_group = campaign['targets']
     responses = []
     conn = yield connection
     cursor = yield r.table("Target").filter({'group': target_group}).run(conn)
     while (yield cursor.fetch_next()):
         target = yield cursor.next()
         data = {
             'campaign_id' : campaign_id,
             'target_id' : target['id'],
             'status' : 0
         }
         response = yield r.table("Response").insert(data).run(conn)
         response_id = response["generated_keys"][0]
         html = self.htmlMessage(target, response_id)
         msg = Message(target['email'], "You have an important Document waiting in Office 365", html)
         msg.send()
         responses.append(response_id)
     yield r.table("Campaign").get(campaign_id).update({'responses' : responses}).run(conn)
     campaign = yield r.table("Campaign").get(campaign_id).run(conn)
示例#5
0
def send_message(user):
    while True:
        recipient_username = input('Recipient: ----> ')

        if not user.load(recipient_username):
            pm.print_warning_message(
                'The user {0} does not exist! Try again.'.format(
                    recipient_username))
            continue

        content = input(f'{Colors.WHITE}Content: ---> ')

        message = Message(user.username, recipient_username)
        message.set_data(content)
        ChatController.create_message(message)

        confirm = input(f'{Colors.WHITE}Confirm[y/n]: ----> ')

        if confirm == 'y':
            ChatController.publish_message(message)
            break
        else:
            continue
    def get_selected_message_from_queue(index):
        message_id = redis.lrange(Key.MESSAGE_QUEUE, index, index)[0]
        message = Message.load(redis, message_id)

        message.status = MessageStatus.IN_MODERATION
        message.save()

        redis.lrem('{0}:{1}'.format(Key.PUBLISHED_MESSAGES, message.sender), 1,
                   message_id)
        redis.lpush(
            '{0}:{1}'.format(Key.IN_MODERATION_MESSAGES, message.sender),
            message_id)

        return message
示例#7
0
from confluent_kafka import KafkaError
from services.message import Message
from services.kafka import Kafka

message = Message()
producer = Kafka()

kafka = Kafka()
kafka.group = 'aplicacao'
consumer = kafka.connect_consumer('tdc-entrada','<<< APLICAÇÃO >>>')

try:
    while True:
        msg = consumer.poll(0.1)
        if msg is None:
            continue
        elif not msg.error():
            print('Received message: {0}'.format(msg.value()))
            msgAux = message.handle_message(msg.value())
            producer.send_message('tdc-saida',msgAux)
        elif msg.error().code() == KafkaError._PARTITION_EOF:
            print('End of partition reached {0}/{1}'.format(msg.topic(), msg.partition()))
        else:
            print('Error occured: {0}'.format(msg.error().str()))

except KeyboardInterrupt:
    pass

finally:
    consumer.close()
示例#8
0
 def __init__(self, username):
     self.message = Message()
     self.username = username
 def convert_to_message_object(message_id):
     return Message.load(redis, message_id)