1 from qqbot.utf8logger import DEBUG 2 import requests 3 import re 4 def onQQMessage(bot, contact, member, content): 5 if content[0]!=‘#‘: 6 return 7 if content[0:4] == ‘#CF#‘: 8 userid = content[5:] 9 reqhttp = "http://codeforces.com/api/user.info?handles="+userid 10 r = requests.get(reqhttp).text 11 if re.search(‘"status":"OK"‘,r)==None: 12 bot.SendTo(contact, "status:ERROR!") 13 bot.SendTo(contact,"cant find this id in codeforces") 14 else : 15 bot.SendTo(contact, "status:OK!") 16 17 endpos = re.search(‘"rating":‘, r).span() 18 endpos=endpos[1] 19 now=endpos 20 while r[now].isdigit(): 21 now=now+1 22 userrating = r[endpos:now] 23 bot.SendTo(contact, userid+" now rating "+userrating) 24 25 endpos = re.search(‘"rank":‘, r).span() 26 endpos=endpos[1] 27 now=endpos+1 28 while r[now]!=‘"‘: 29 now=now+1 30 userrank = r[endpos+1:now] 31 bot.SendTo(contact, userid+" rank "+userrank) 32 33 endpos = re.search(‘"maxRating":‘, r).span() 34 endpos=endpos[1] 35 now=endpos 36 while r[now].isdigit(): 37 now=now+1 38 maxrating = r[endpos:now] 39 bot.SendTo(contact, userid+" maxRating "+maxrating) 40 41 reqhttp = "http://codeforces.com/api/user.status?handle=" + userid+"&from=1&count=5" 42 r = requests.get(reqhttp).text 43 id = re.findall(‘"contestId":[0-9]*‘, r) 44 index = re.findall(‘"index":"\w"‘, r) 45 verdict = re.findall(‘"verdict":"[a-zA-Z_]*"‘, r) 46 bot.SendTo(contact,"Recent 5 submissions:") 47 for i in range(len(index)): 48 bot.SendTo(contact,id[i * 3] + index[i][-2]+" " + verdict[i]) 49 else: 50 bot.SendTo(contact, "???????")