如果语句正常工作,如何制作嵌套的嵌套?

时间:2019-08-09 06:56:30

标签: python

当joinarea触发时,而不是输出“人员加入区域”!它循环返回到if语句,在该语句中检查交易是否为空。我正在尝试将其嵌套在elif语句中,但不确定语法在哪里出错。

def tradescan(d):
    logfile = open("log.txt","r")
    loglines = follow(logfile)
    for line in loglines:
        trade = re.match("([0-9]{4}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}).*\\[INFO Client [0-9]*] @(To|From) (?:<(.+)> )?([a-zA-Z_, ]+): (.+)", line)
        joinedarea = re.match("([0-9]{4}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}).*\\[INFO Client [0-9]*] : (\\S+) has joined the area\\.", line)
        #print(joinedarea[2])
        incoming = "From"
        if trade is None:
            print("Scanning game for appropriate trades...")
        elif (trade[2] == incoming):
            user = trade[4]
            splitat = 25
            r = trade[5][splitat:]
            split = r.split()
            int_list = re.findall("[0-9]+", r)
            try:
                price1 = int_list[0]
            except IndexError:
                print("Trade Mismatch - ignoring trade from", user)
                continue

            try:
                price2 = int_list[1]
            except IndexError:
                print("Trade Mismatch - ignoring trade from", user)
                continue

            #print(price1, price2)
            matches = {x for x in d if x in r}
            items = list(matches)
            try:
                iname1 = items[0]
            except IndexError:
                print("Trade Mismatch - ignoring trade from", user)
                continue

            try:
                iname2 = items[1]
            except IndexError:
                print("Trade Mismatch - ignoring trade from", user)
                continue

            print(Fore.YELLOW + Back.MAGENTA + Style.BRIGHT + user, "wants", price1, iname1, "for", price2, iname2 + Style.RESET_ALL),
            py.moveTo(567, 26, 2)
            py.click()
            py.typewrite(['enter'])
            py.typewrite('/invite ' + user + '\n')
            try:
                userjoin = joinedarea[2]
            except TypeError:
                print("Waiting for", user, "to join area...")
                continue
            if joinedarea:
                print(userjoin, "joined area!")

0 个答案:

没有答案