Ejemplo n.º 1
0
def div(a, b, lv):
    e = Echo("div", lv)
    e.ask("What's the result of {0} / {1}?".format(to_string(a), to_string(b)))
    if b == 0:
        raise ZeroDivisionError
    e.answer("{0}.".format(a/b))
    return a/b
Ejemplo n.º 2
0
def map_(f, lat, lv):
    e = Echo("map", lv)
    e.ask("What's the result of mapping {0} to each element of {1}".format(to_string(f), to_string(lat)))
    retval = []
    for one in lat:
        retval.append(f(one, lv))
    e.answer("It's {0}".format(to_string(retval)))
    return retval
Ejemplo n.º 3
0
def main():
    app = EchoApp()

    echo = Echo()
    echo.msg = '1931'

    client = Client(app)
    #client.connect('127.0.0.1', 1931, partial(callback, client, echo))
    client.connect('127.0.0.1', 1327, partial(callback, client, echo))

    tornado.ioloop.IOLoop.instance().start()
Ejemplo n.º 4
0
def is_null(s, lv):
    e = Echo("null?", lv)
    e.ask("Is {0} an empty list?".format(to_string(s)))
    if isa(s, list):
        e.answer("Yes.") if s == [] else e.answer("Nope.")
        return s == []
    else:
        e.answer("No answer since you can only ask null? of a list")
        return None
Ejemplo n.º 5
0
def is_eq(a, b, lv):
    e = Echo("eq?", lv)
    e.ask("Does {0} eq to {1}?".format(to_string(a), to_string(b)))
    if isa(a, str) and isa(b, str):
        e.answer("Yes.") if a == b else e.answer("Nope.")
        return a == b
    else:
        e.answer("No answer because eq? only accepts two non-numeric atoms.")
        return None
Ejemplo n.º 6
0
def is_zero(n, lv):
    e = Echo("zero?", lv)
    e.ask("Is {0} zero?".format(to_string(n)))
    if isa(n, int) or isa(n, float):
        e.answer("Yes.") if n == 0 else e.answer("Nope.")
        if n == 0: return True
        else: return False
    else:
        e.answer("No answer since you can only ask zero? of a number")
        return None
Ejemplo n.º 7
0
def is_null(s, lv):
    e = Echo("null?", lv)
    e.ask("Is {0} an empty list?".format(to_string(s)))
    if isa(s, list):
        e.answer("Yes.") if s==[] else e.answer("Nope.")
        return s==[]
    else: 
        e.answer("No answer since you can only ask null? of a list")
        return None
Ejemplo n.º 8
0
def is_member(a, lat, lv):
    e = Echo("member?", lv)
    e.ask("Is {0} a member of {1}?".format(to_string(a), to_string(lat)))
    for atom in lat:
        if a == atom:
            e.answer("Yes.")
            return True
    e.answer("Nope.")
    return False
Ejemplo n.º 9
0
def is_number(s, lv):
    e = Echo("number?", lv)
    e.ask("Is {0} number?".format(to_string(s)))
    if isa(s, int) or isa(s, float):
        e.answer("Yes.")
        return True
    else:
        e.answer("Nope.")
        return False
Ejemplo n.º 10
0
def cons(x, y, lv):
    e = Echo("cons", lv)
    e.ask("What's cons of {0} and {1}?".format(to_string(x), to_string(y)))
    if isa(y, list):
        e.answer("{0}.".format(to_string([x] + y)))
        return [x] + y
    else:
        e.answer("No answer, since the second argument to cons must be list.")
        return None
Ejemplo n.º 11
0
def is_eq(a, b, lv):
    e = Echo("eq?", lv)
    e.ask("Does {0} eq to {1}?".format(to_string(a), to_string(b)))
    if isa(a, str) and isa(b, str):
        e.answer("Yes.") if a==b else e.answer("Nope.")
        return a==b
    else:
        e.answer("No answer because eq? only accepts two non-numeric atoms.")
        return None
Ejemplo n.º 12
0
    def __init__(self,
                 name: str,
                 children: int,
                 options: Optional[ResourceOptions] = None):
        super().__init__('testcomponent:index:Component', name, {}, options)

        for i in range(0, children):
            Echo(f'child-{name}-{i+1}', i + 1, ResourceOptions(parent=self))
Ejemplo n.º 13
0
def is_zero(n, lv):
    e = Echo("zero?", lv)
    e.ask("Is {0} zero?".format(to_string(n)))
    if isa(n, int) or isa(n, float):
        e.answer("Yes.") if n==0 else e.answer("Nope.")
        if n==0: return True
        else: return False
    else:
        e.answer("No answer since you can only ask zero? of a number")
        return None
Ejemplo n.º 14
0
def ping():
    transport = TSocket.TSocket('127.0.0.1', 9099)
    tranport = TTransport.TFramedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(tranport)
    client = Echo.Client(protocol)
    tranport.open()
    client.ping()
    tranport.close()
    print("ping ...")
Ejemplo n.º 15
0
def echo(s):
    transport = TSocket.TSocket('127.0.0.1', 9090)
    tranport = TTransport.TFramedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(tranport)
    client = Echo.Client(protocol)
    tranport.open()
    s = client.echo(s)
    tranport.close()

    return s
Ejemplo n.º 16
0
 def setUp(self):
     self.pro = pyasynchio.Proactor()
     self.port = 40274
     self.echo = Echo(self.pro)
     self.done = False
     self.pro.open_stream_accept(self.echo, ('', self.port))
     import thread
     thread.start_new_thread(self.thr_func, ())
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.sock.connect(('127.0.0.1', self.port))
Ejemplo n.º 17
0
def is_number(s, lv):
    e = Echo("number?", lv)
    e.ask("Is {0} number?".format(to_string(s)))
    if isa(s, int) or isa(s, float):
        e.answer("Yes.")
        return True
    else:
        e.answer("Nope.")
        return False
Ejemplo n.º 18
0
def is_member(a, lat, lv):
    e = Echo("member?", lv)
    e.ask("Is {0} a member of {1}?".format(to_string(a), to_string(lat)))
    for atom in lat:
        if a == atom:
            e.answer("Yes.")
            return True
    e.answer("Nope.")
    return False
Ejemplo n.º 19
0
def cons(x, y, lv):
    e = Echo("cons", lv)
    e.ask("What's cons of {0} and {1}?".format(to_string(x), to_string(y)))
    if isa(y, list):
        e.answer("{0}.".format(to_string([x]+y)))
        return [x]+y
    else: 
        e.answer("No answer, since the second argument to cons must be list.")
        return None
Ejemplo n.º 20
0
def div(a, b, lv):
    e = Echo("div", lv)
    e.ask("What's the result of {0} / {1}?".format(to_string(a), to_string(b)))
    if b == 0:
        raise ZeroDivisionError
    e.answer("{0}.".format(a / b))
    return a / b
Ejemplo n.º 21
0
    def __init__(self,
                 username=None,
                 password=None,
                 access_token=None,
                 request=None):

        self.request = request or PlayNicelyRequest(username, password)

        self.projects = Projects(self.request)
        self.milestones = Milestones(self.request)
        self.items = Items(self.request)
        self.users = Users(self.request)
        self.echo = Echo(self.request)
Ejemplo n.º 22
0
def create_client():
    # Make socket
    transport = TSocket.TSocket('localhost', 9090)

    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)

    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    # Create a client to use the protocol encoder
    client = Echo.Client(protocol)

    return (client, transport)
Ejemplo n.º 23
0
def map_(f, lat, lv):
    e = Echo("map", lv)
    e.ask("What's the result of mapping {0} to each element of {1}".format(
        to_string(f), to_string(lat)))
    retval = []
    for one in lat:
        retval.append(f(one, lv))
    e.answer("It's {0}".format(to_string(retval)))
    return retval
Ejemplo n.º 24
0
 def __init__(self,
              name: str,
              echo: Input[Any],
              secret: Input[str],
              opts: Optional[ResourceOptions] = None):
     super().__init__('testcomponent:index:Component', name, {}, opts)
     self.echo = pulumi.Output.from_input(echo)
     resource = Echo(f'child-{name}', echo, ResourceOptions(parent=self))
     self.child_id = resource.id
     self.secret = secret
     self.register_outputs({
         'childId': self.child_id,
         'echo': self.echo,
         'secret': self.secret
     })
Ejemplo n.º 25
0
def sub(a, b, lv):
    e = Echo("sub", lv)
    e.ask("What's the result of {0} - {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a-b))
    return a-b
Ejemplo n.º 26
0
def car(x, lv, verbose=False):
    e = Echo("car", lv)
    e.ask("What's car of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, because you cannot ask for the car of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer(
                "No answer, because you cannot ask for the car of the empty list."
            )
            return None
        else:
            e.answer("{0}.".format(to_string(x[0])))
            return x[0]
    else:
        e.answer("No answer, because car is only for non-empty lists.")
        return None
Ejemplo n.º 27
0
def expt(n, m, lv):
    e = Echo("expt", lv)
    e.ask("What is rasing {0} to the power of {1}".format(
        to_string(n), to_string(m)))
    e.answer("{0}.".format(n**m))
    return n**m
Ejemplo n.º 28
0
def lt(a, b, lv):
    e = Echo("lt", lv)
    e.ask("Is {0} less than {1}?".format(a, b))
    e.answer("Yes.") if a < b else e.answer("Nope.")
    return a < b
Ejemplo n.º 29
0
def cdr(x, lv):
    e = Echo("cdr", lv)
    e.ask("What's cdr of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, since you cannot ask for the cdr of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer("No answer, since you cannot ask for the cdr of the empty list.")
            return None
        else:
            e.answer("{0}.".format(to_string(x[1:])))
            return x[1:]
    else:
        e.answer("No answer, because cdr is only for non-empty lists.")
        return None
Ejemplo n.º 30
0
def expt(n, m, lv):
    e = Echo("expt", lv)
    e.ask("What is rasing {0} to the power of {1}".format(to_string(n), to_string(m)))
    e.answer("{0}.".format(n**m))
    return n**m
Ejemplo n.º 31
0
def add1(n, lv):
    e = Echo("add1", lv)
    e.ask("What is the result of adding 1 to {0}?".format(to_string(n)))
    e.answer("{0}.".format(n+1))
    return n+1
Ejemplo n.º 32
0
def is_atom(s, lv):
    e = Echo("atom?", lv)
    e.ask("Is {0} an atom?".format(to_string(s)))
    e.answer("Yes.") if isa(s, str) or isa(s, int) or isa(s, float) else e.answer("Nope.")
    return isa(s, str) or isa(s, int) or isa(s, float)
Ejemplo n.º 33
0
def is_equal(a, b, lv):
    e = Echo("equal?", lv)
    e.ask("Does {0} equal to {1}?".format(to_string(a), to_string(b)))
    e.answer("Yes.") if a==b else e.answer("Nope.")
    return a==b
Ejemplo n.º 34
0
def gt(a, b, lv):
    e = Echo("gt", lv)
    e.ask("Is {0} greater than {1}?".format(a, b))
    e.answer("Yes.") if a > b else e.answer("Nope.")
    return a > b
Ejemplo n.º 35
0
def not_(s, lv):
    e = Echo("not", lv)
    e.ask("What's opposite to {0}?".format(to_string(s)))
    e.answer("It's {0}".format(not s))
    return not s
Ejemplo n.º 36
0
def eq(a, b, lv):
    e = Echo("eq", lv)
    e.ask("Is {0} = {1}?".format(a, b))
    e.answer("Yes.") if a == b else e.answer("Nope.")
    return a == b
Ejemplo n.º 37
0
def lte(a, b, lv):
    e = Echo("lte", lv)
    e.ask("Is {0} less or equal than {1}?".format(a, b))
    e.answer("Yes.") if a <= b else e.answer("Nope")
    return a <= b
Ejemplo n.º 38
0
def mult(a, b, lv):
    e = Echo("mult", lv)
    e.ask("What's the result of {0} * {1}?".format(to_string(a) ,to_string(b)))
    e.answer("{0}.".format(a*b))
    return a*b
Ejemplo n.º 39
0
def is_atom(s, lv):
    e = Echo("atom?", lv)
    e.ask("Is {0} an atom?".format(to_string(s)))
    e.answer("Yes.") if isa(s, str) or isa(s, int) or isa(
        s, float) else e.answer("Nope.")
    return isa(s, str) or isa(s, int) or isa(s, float)
Ejemplo n.º 40
0
def mult(a, b, lv):
    e = Echo("mult", lv)
    e.ask("What's the result of {0} * {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a * b))
    return a * b
Ejemplo n.º 41
0
def sub1(n, lv):
    e = Echo("sub1", lv)
    e.ask("What is the result of subtracting 1 from {0}?".format(to_string(n)))
    e.answer("{0}.".format(n-1))
    return n-1
Ejemplo n.º 42
0
def run(queue):
    while True:
        if not queue.empty():
            d = queue.get_nowait()
            if d == 'END':
                while not queue.empty():
                    queue.get_nowait()
                break

        try:
            email = os.environ['EMAIL']
            password = os.environ['PASSWORD']    
            client = MyClient(email,password,queue)
            client.onMessageListeners = set([RotateImage(), ChooseOne(), RollADice(), Echo(), Insult(), IsActive(), #KeepChatClean(), 
                Rip(), SayManyTimes(), StupidReply(), YoutubeLink(), PostMeme()])
            client.listen()
        except Exception as e:
            print(e)

    print('Finished')
Ejemplo n.º 43
0
def car(x, lv, verbose=False):
    e = Echo("car", lv)
    e.ask("What's car of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, because you cannot ask for the car of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer("No answer, because you cannot ask for the car of the empty list.")
            return None
        else:
            e.answer("{0}.".format(to_string(x[0])))
            return x[0]
    else:
         e.answer("No answer, because car is only for non-empty lists.")
         return None
Ejemplo n.º 44
0
def is_equal(a, b, lv):
    e = Echo("equal?", lv)
    e.ask("Does {0} equal to {1}?".format(to_string(a), to_string(b)))
    e.answer("Yes.") if a == b else e.answer("Nope.")
    return a == b
Ejemplo n.º 45
0
def add(a, b, lv):
    e = Echo("add", lv)
    e.ask("What's the result of {0} + {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a+b))
    return a+b
Ejemplo n.º 46
0
def gte(a, b, lv):
    e = Echo("gte", lv)
    e.ask("Is {0} greater or equal than {1}?".format(a, b))
    e.answer("Yes.") if a >= b else e.answer("Nope.")
    return a >= b
Ejemplo n.º 47
0
    def echo(self, s):
        self.inc_count()
        return s

    def add(self, p):
        x = p.workout_id
        self.inc_count()

    def count(self):
        return self.c

    def reset(self):
        self.c = {}
        return True


if __name__ == '__main__':
    handler = EchoHandler()
    processor = Echo.Processor(handler)
    transport = TSocket.TServerSocket(port=9090)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()

    server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
    print "starting server"
    try:
        server.serve()
    except (SystemExit, KeyboardInterrupt):
        server.stop()
Ejemplo n.º 48
0
def sub(a, b, lv):
    e = Echo("sub", lv)
    e.ask("What's the result of {0} - {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a - b))
    return a - b
Ejemplo n.º 49
0
def add(a, b, lv):
    e = Echo("add", lv)
    e.ask("What's the result of {0} + {1}?".format(to_string(a), to_string(b)))
    e.answer("{0}.".format(a + b))
    return a + b
Ejemplo n.º 50
0
    # Trial2 가 텐서보드에 뜨는 태그 -> 실행 할 때 마다 바꾸면 좋음
    tf.summary.scalar('Tetris_v2.0', addition)
    summary_op = tf.summary.merge_all()
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        # 저장경로
        writer = tf.summary.FileWriter('./tetris_logs', sess.graph)

        option = {
            "parent_count": 5,
            "gene_count": 50,
            "gene_length": 6,
            "mutation_probability": 0.05
        }
        echo = Echo(option)
        generation_limit = 100

        while True:
            print('=======================')
            print(str(echo.generation) + '세대 유전자들')
            #parameter로 들어간게 점수임
            total = echo.next_generation()

            print(str(echo.generation) + '세대 상위 유전자')
            score_avg = total / option["parent_count"]
            for parent in echo.parents:
                print(parent.status, parent.score)

            # 앞에서 define 한 변수들에게 값을 씌워줌
            var1 = np.float64(0)
Ejemplo n.º 51
0
    def do_crawl(self):
        """
        执行爬取
        """
        echo = Echo()
        url_count = 0
        url_num = len(self.url.url)
        while url_count < url_num:
            data_count = 0
            url_dict = self.url.url[url_count]
            req = requests.Request(method=url_dict['method'], url=url_dict['value'])

            #加入cookies,data和headers
            if self.parse.cookie_range[2] >= url_count + 1 >= self.parse.cookie_range[1]:
                req.cookies = self.cookie
            if len(url_dict['data']) > data_count:
                req.data = url_dict['data'][data_count]
                data_count += 1
            for ele in url_dict['addparam']:
                try:
                    req.data[ele[1]] = self.url.url[int(ele[0])-1]['text'][0]
                except IndexError:
                    print "Error!No additional param found."

            if len(self.header.header) > 0:
                req.headers = self.header.header

            s = requests.Session()
            prepped = s.prepare_request(req)
            self.resp = s.send(prepped, stream=True)
            if self.resp.status_code == 200:
                if url_count+1 == self.parse.cookie_range[0]:
                    self.cookie = self.resp.cookies
            else:
                print "status_code:{0}".format(self.resp.status_code)


            #数据分析
            if url_dict['type'] == 't':
                analyze = Analyze()
                text_list = analyze.analyze(self.resp.text, url_dict['re'])
                self.url.url[url_count]['text'] = text_list


            #输出结果
            if url_dict['type'] == 't':
                pretext = url_dict['value'] + '\n' + ''.join(str(s) + '\n' for s in url_dict['data']) + '\n\n'
                self.text = ''.join(s + '\n' for s in text_list)
            elif url_dict['type'] == 'b':
                m = url_dict['value'].rfind('/')
                pretext = url_dict['value'][m+1:]
                self.text = self.resp.iter_content(chunk_size=128)
            else:
                raise ValueError('[Type] name not found')
            if self.parse.echo_method != 'xls':
                echo.echo(self.parse.echo_method, pretext, self.text, url_dict['type'], url_count, data_count)
            else:
                echo.echo_to_xls(self.text, self.parse.xls_list[0], self.parse.xls_list[1], self.parse.xls_list[2], self.parse.xls_title)

            if data_count == len(url_dict['data']):
                url_count += 1
Ejemplo n.º 52
0
def sub1(n, lv):
    e = Echo("sub1", lv)
    e.ask("What is the result of subtracting 1 from {0}?".format(to_string(n)))
    e.answer("{0}.".format(n - 1))
    return n - 1
Ejemplo n.º 53
0
import timeit
import gevent

if __name__ == '__main__':
    # Make socket
    transport = TSocket.TSocket('localhost', 9090)

    # Buffering is critical. Raw sockets are very slow
    transport = TTransport.TBufferedTransport(transport)

    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    # Create a client to use the protocol encoder
    client = Echo.Client(protocol)

    def worker():
        try:
            client.noop()
        except:
            print 'worker failed'

    # Connect!
    transport.open()

    for n in [1000, 10000, 100000]:
        client.reset()

        for _ in xrange(n):
            gevent.spawn(worker)
Ejemplo n.º 54
0
def cdr(x, lv):
    e = Echo("cdr", lv)
    e.ask("What's cdr of {0}?".format(to_string(x)))
    if isa(x, str):
        e.answer("No answer, since you cannot ask for the cdr of an atom.")
        return None
    elif isa(x, list):
        if x == []:
            e.answer(
                "No answer, since you cannot ask for the cdr of the empty list."
            )
            return None
        else:
            e.answer("{0}.".format(to_string(x[1:])))
            return x[1:]
    else:
        e.answer("No answer, because cdr is only for non-empty lists.")
        return None
Ejemplo n.º 55
0
from twisted.internet import reactor
from twisted.words.protocols.jabber.jid import JID
from wokkel.client import XMPPClient


from echo import Echo
from roster import Roster

with open('account', 'r') as f:
    account = f.readlines()

jid = JID(account[0].rstrip('\n'))
password = account[1].rstrip('\n')

client = XMPPClient(jid, password)

echo = Echo()
roster = Roster()

roster.setHandlerParent(client)
echo.setHandlerParent(client)

client.startService()
reactor.run()
Ejemplo n.º 56
0
def add1(n, lv):
    e = Echo("add1", lv)
    e.ask("What is the result of adding 1 to {0}?".format(to_string(n)))
    e.answer("{0}.".format(n + 1))
    return n + 1