CF getrating qqbot.py

Posted Meternal

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF getrating qqbot.py相关的知识,希望对你有一定的参考价值。

 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的主要内容,如果未能解决你的问题,请参考以下文章

小伙用Python编写QQ机器人和女朋友聊了一下午都没被发现?

MediaMetadataCompact getRating

如何从后台弹出片段

cf 模拟

在初始化之前使用结构

使用 lambda 的 Blazor 文本插值