Example #1
0
def getRedis():
    clientCreator = protocol.ClientCreator(reactor, RedisClient)
    return clientCreator.connectTCP(REDIS_HOST, REDIS_PORT)
Example #2
0
def main():

    # first parse args

    parser = ArgumentParser(
        description="Script for broadcasting messages in ICQ.")

    parser.add_argument(
        "--messages-file",
        help=
        "Path to messages.txt file which contains messages: one message per line"
    )
    parser.add_argument(
        "-m",
        "--message",
        help=
        "Text message which should be sent. You can also specify --messages-file if you want to send bulk of messages"
    )
    parser.add_argument("-u", "--user", help="UIN of user", required=True)
    parser.add_argument("-p",
                        "--password",
                        help="Password from account",
                        required=True)
    parser.add_argument(
        '--sleep-time',
        help=
        "Time between sending in minutes. By default one hour (60 minutes)",
        default="60")
    parser.add_argument(
        "--groups-only",
        action="store_true",
        help="If flag is present messages will be sent only to groups.")
    parser.add_argument(
        "--log-level",
        help=
        "Logging level, by default is INFO(may be too verbose). Can be one from INFO, WARN, ERROR",
        default="INFO")

    ns = parser.parse_args(sys.argv[1:])

    sleep_time = int(ns.sleep_time)

    LOGGER.setLevel(ns.log_level)

    if not ns.message and not ns.messages_file:
        print >> sys.stderr, "You should specify message or message file!"
        sys.exit(1)

    messages = []
    if ns.messages_file:
        with open(ns.messages_file, "r") as fd:
            text = fd.read()

            messages = [item for item in text.split("\n\n\n") if item]
    else:
        messages = [ns.message]

    # set Oscar parameters
    B.UIN = ns.user
    B.MESSAGES = messages
    B.SLEEP_TIME = sleep_time
    B.SEND_TO_GROUPS_ONLY = ns.groups_only

    def callback(oscarConnection):
        ":type oscarConnection: B"

    d = Deferred()
    d.addCallback(callback)
    protocol.ClientCreator(reactor, OA, ns.user, ns.password,
                           icq=icqMode).connectTCP(*host)
    reactor.run()
Example #3
0
 def __init__(self, host, port):
     self.deferred = protocol.ClientCreator(reactor,
                                            ClusterReceiver).connectTCP(
                                                host, port)
Example #4
0
 def channelOpen(self, specificData):
     cc = protocol.ClientCreator(reactor, SSHForwardingClient, self)
     log.msg("connecting to %s:%i" % self.hostport)
     cc.connectTCP(*self.hostport).addCallbacks(self._setClient,
                                                self._close)
Example #5
0
                      instance).addCallback(self.chatJoined)

    def chatJoined(self, chat):
        print 'joined chat room', chat.name
        print 'members:', map(lambda x: x.name, chat.members)

    def chatReceiveMessage(self, chat, user, message):
        print 'message to', chat.name, 'from', user.name, ':', message
        if user.name != self.name: chat.sendMessage(user.name + ': ' + message)
        if message.find('leave') != -1 and chat.name != '%s Chat' % SN:
            chat.leaveChat()

    def chatMemberJoined(self, chat, member):
        print member.name, 'joined', chat.name

    def chatMemberLeft(self, chat, member):
        print member.name, 'left', chat.name
        print 'current members', map(lambda x: x.name, chat.members)
        if chat.name != "%s Chat" % SN and len(chat.members) == 1:
            print 'leaving', chat.name
            chat.leaveChat()


class OA(oscar.OscarAuthenticator):
    BOSClass = B


protocol.ClientCreator(reactor, OA, SN, PASS,
                       icq=icqMode).connectTCP(*hostport)
reactor.run()
Example #6
0
 def initialise(self):
     MySub = RedisSubscriber
     MySub.messageReceived = self.messageReceived
     clientCreator = protocol.ClientCreator(reactor, MySub)
     self.redis = yield clientCreator.connectTCP(REDIS_HOST, REDIS_PORT)
     defer.returnValue(True)
Example #7
0
 def initialise(self):
     clientCreator = protocol.ClientCreator(reactor, Redis)
     self.redis = yield clientCreator.connectTCP(REDIS_HOST, REDIS_PORT)
     defer.returnValue(True)
Example #8
0
        return self.looping_call.start(0)

    def consume_from_queue(self, queue):
        d = queue.get()

        return d.addCallback(lambda result: self.handle_payload(*result))

    def handle_payload(self, channel, method, properties, body):
        print(body)


if __name__ == "__main__":
    consumer1 = Consumer()
    consumer2 = Consumer()

    parameters = ConnectionParameters()
    cc = protocol.ClientCreator(reactor,
                                TwistedProtocolConnection,
                                parameters)
    d1 = cc.connectTCP("individuos", 5672)
    d1.addCallback(lambda protocol: protocol.ready)
    d1.addCallback(consumer1.on_connected)
    d1.addErrback(log.err)

    d2 = cc.connectTCP("individuosEntrenados", 5672)
    d2.addCallback(lambda protocol: protocol.ready)
    d2.addCallback(consumer2.on_connected)
    d2.addErrback(log.err)

    reactor.run()