当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!")