Spaces:
Build error
Build error
Update tools/codeforces.py
Browse files- tools/codeforces.py +124 -1
tools/codeforces.py
CHANGED
|
@@ -125,4 +125,127 @@ def intersect(sets:List[List[str]])-> List[str]: #it's import to specify the ret
|
|
| 125 |
for s in sorted_lists:
|
| 126 |
result &= set(s)
|
| 127 |
|
| 128 |
-
return list(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
for s in sorted_lists:
|
| 126 |
result &= set(s)
|
| 127 |
|
| 128 |
+
return list(result)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
from typing import Dict
|
| 132 |
+
import requests
|
| 133 |
+
|
| 134 |
+
# Assume BASE_URL is defined elsewhere; for example:
|
| 135 |
+
BASE_URL = "https://codeforces.com/api/"
|
| 136 |
+
|
| 137 |
+
def get_user_info(handle: str) -> Dict:
|
| 138 |
+
"""Fetches user information from Codeforces
|
| 139 |
+
Args:
|
| 140 |
+
handle: The Codeforces user handle
|
| 141 |
+
"""
|
| 142 |
+
response = requests.get(f"{BASE_URL}user.info?handles={handle}").json()
|
| 143 |
+
return response.get("result", [{}])[0]
|
| 144 |
+
|
| 145 |
+
@tool
|
| 146 |
+
def get_contribution(handle: str) -> int:
|
| 147 |
+
"""Fetches the contribution of a Codeforces user.
|
| 148 |
+
Args:
|
| 149 |
+
handle: The Codeforces user handle
|
| 150 |
+
"""
|
| 151 |
+
user_info = get_user_info(handle)
|
| 152 |
+
return user_info.get("contribution", 0)
|
| 153 |
+
|
| 154 |
+
@tool
|
| 155 |
+
def get_lastOnlineTimeSeconds(handle: str) -> int:
|
| 156 |
+
"""Fetches the last online time (in seconds) of a Codeforces user.
|
| 157 |
+
Args:
|
| 158 |
+
handle: The Codeforces user handle
|
| 159 |
+
"""
|
| 160 |
+
user_info = get_user_info(handle)
|
| 161 |
+
return user_info.get("lastOnlineTimeSeconds", 0)
|
| 162 |
+
|
| 163 |
+
@tool
|
| 164 |
+
def get_organization(handle: str) -> str:
|
| 165 |
+
"""Fetches the organization of a Codeforces user.
|
| 166 |
+
Args:
|
| 167 |
+
handle: The Codeforces user handle
|
| 168 |
+
"""
|
| 169 |
+
user_info = get_user_info(handle)
|
| 170 |
+
return user_info.get("organization", "")
|
| 171 |
+
|
| 172 |
+
@tool
|
| 173 |
+
def get_rating(handle: str) -> int:
|
| 174 |
+
"""Fetches the current rating of a Codeforces user.
|
| 175 |
+
Args:
|
| 176 |
+
handle: The Codeforces user handle
|
| 177 |
+
"""
|
| 178 |
+
user_info = get_user_info(handle)
|
| 179 |
+
return user_info.get("rating", 0)
|
| 180 |
+
|
| 181 |
+
@tool
|
| 182 |
+
def get_friendOfCount(handle: str) -> int:
|
| 183 |
+
"""Fetches the friend count of a Codeforces user.
|
| 184 |
+
Args:
|
| 185 |
+
handle: The Codeforces user handle
|
| 186 |
+
"""
|
| 187 |
+
user_info = get_user_info(handle)
|
| 188 |
+
return user_info.get("friendOfCount", 0)
|
| 189 |
+
|
| 190 |
+
@tool
|
| 191 |
+
def get_titlePhoto(handle: str) -> str:
|
| 192 |
+
"""Fetches the title photo URL of a Codeforces user.
|
| 193 |
+
Args:
|
| 194 |
+
handle: The Codeforces user handle
|
| 195 |
+
"""
|
| 196 |
+
user_info = get_user_info(handle)
|
| 197 |
+
return user_info.get("titlePhoto", "")
|
| 198 |
+
|
| 199 |
+
@tool
|
| 200 |
+
def get_rank(handle: str) -> str:
|
| 201 |
+
"""Fetches the rank of a Codeforces user.
|
| 202 |
+
Args:
|
| 203 |
+
handle: The Codeforces user handle
|
| 204 |
+
"""
|
| 205 |
+
user_info = get_user_info(handle)
|
| 206 |
+
return user_info.get("rank", "")
|
| 207 |
+
|
| 208 |
+
@tool
|
| 209 |
+
def get_handle(handle: str) -> str:
|
| 210 |
+
"""Fetches the handle (username) of a Codeforces user.
|
| 211 |
+
Args:
|
| 212 |
+
handle: The Codeforces user handle
|
| 213 |
+
"""
|
| 214 |
+
user_info = get_user_info(handle)
|
| 215 |
+
return user_info.get("handle", "")
|
| 216 |
+
|
| 217 |
+
@tool
|
| 218 |
+
def get_maxRating(handle: str) -> int:
|
| 219 |
+
"""Fetches the maximum rating of a Codeforces user.
|
| 220 |
+
Args:
|
| 221 |
+
handle: The Codeforces user handle
|
| 222 |
+
"""
|
| 223 |
+
user_info = get_user_info(handle)
|
| 224 |
+
return user_info.get("maxRating", 0)
|
| 225 |
+
|
| 226 |
+
@tool
|
| 227 |
+
def get_avatar(handle: str) -> str:
|
| 228 |
+
"""Fetches the avatar URL of a Codeforces user.
|
| 229 |
+
Args:
|
| 230 |
+
handle: The Codeforces user handle
|
| 231 |
+
"""
|
| 232 |
+
user_info = get_user_info(handle)
|
| 233 |
+
return user_info.get("avatar", "")
|
| 234 |
+
|
| 235 |
+
@tool
|
| 236 |
+
def get_registrationTimeSeconds(handle: str) -> int:
|
| 237 |
+
"""Fetches the registration time (in seconds) of a Codeforces user.
|
| 238 |
+
Args:
|
| 239 |
+
handle: The Codeforces user handle
|
| 240 |
+
"""
|
| 241 |
+
user_info = get_user_info(handle)
|
| 242 |
+
return user_info.get("registrationTimeSeconds", 0)
|
| 243 |
+
|
| 244 |
+
@tool
|
| 245 |
+
def get_maxRank(handle: str) -> str:
|
| 246 |
+
"""Fetches the maximum rank achieved by a Codeforces user.
|
| 247 |
+
Args:
|
| 248 |
+
handle: The Codeforces user handle
|
| 249 |
+
"""
|
| 250 |
+
user_info = get_user_info(handle)
|
| 251 |
+
return user_info.get("maxRank", "")
|