码迷,mamicode.com
首页 > 其他好文 > 详细

CF getrating qqbot.py

时间:2018-01-01 23:49:33      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:arc   sub   content   turn   ber   pos   get   rom   range   

 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, "???????")

 

CF getrating qqbot.py

标签:arc   sub   content   turn   ber   pos   get   rom   range   

原文地址:https://www.cnblogs.com/Meternal/p/8168927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!