Beispiel #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
Beispiel #2
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))
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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))
Beispiel #11
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)
Beispiel #12
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
     })
Beispiel #13
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
Beispiel #14
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
Beispiel #15
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
Beispiel #16
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
Beispiel #17
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
Beispiel #18
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
Beispiel #19
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
Beispiel #20
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
Beispiel #21
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
Beispiel #22
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
Beispiel #23
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
Beispiel #24
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)
Beispiel #25
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')
Beispiel #26
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
Beispiel #27
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
Beispiel #28
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
Beispiel #29
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)
Beispiel #30
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