Skip to content

Commit 09ca826

Browse files
committed
Experimental support of asyncLuoguAPI(Tag 0.0.2)
1 parent 2b1ea78 commit 09ca826

File tree

5 files changed

+100
-44
lines changed

5 files changed

+100
-44
lines changed

README.md

Lines changed: 86 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# luogu-api-python
2-
A Python implementation of the Luogu API
2+
A Python implementation of the Luogu API.
33

44
## Project Description
55

@@ -30,6 +30,8 @@ To install the package from source, follow these steps:
3030
3131
## Usage
3232
33+
### Synchronous API
34+
3335
Here is an example of how to use the package:
3436
3537
```python
@@ -44,6 +46,28 @@ for problem in problems:
4446
print(problem.title)
4547
```
4648

49+
### Asynchronous API (Experimental)
50+
51+
The package also provides experimental support for async operations:
52+
53+
```python
54+
import asyncio
55+
import pyLuogu
56+
57+
# Initialize the async API without cookies
58+
luogu = pyLuogu.asyncLuoguAPI()
59+
60+
async def main():
61+
async with luogu:
62+
problems = (await luogu.get_problem_list()).problems
63+
for problem in problems:
64+
print(problem.title)
65+
66+
asyncio.run(main())
67+
```
68+
69+
Note: The async API is currently experimental and subject to changes.
70+
4771
## Contributing
4872

4973
Contributions are welcome! Please open an issue or submit a pull request.
@@ -77,42 +101,64 @@ If you find a bug or have a feature request, please open an issue on GitHub. Pro
77101
78102
## Todo List
79103
80-
Methods of class `LuoguAPI`
81-
82-
- [x] Problem
83-
- [x] get_problem_list
84-
- [x] get_team_problem_list
85-
- [x] get_problem
86-
- [x] get_problem_settings
87-
- [x] update_problem_settings
88-
- [x] update_testcases_settings
89-
- [x] create_problem
90-
- [x] delete_problem
91-
- [x] transfer_problem
92-
- [ ] download_testcases
93-
- [ ] upload_testcases
94-
- [x] User
95-
- [x] get_user
96-
- [x] get_user_info
97-
- [x] get_user_followings_list
98-
- [x] get_user_followers_list
99-
- [x] get_user_blacklist
100-
- [x] search_user
101-
- [x] UserOperation
102-
- [ ] login
103-
- [ ] logout
104-
- [x] me
105-
- [ ] submit_code
106-
- [x] get_created_problem_list
107-
- [ ] get_created_problemset_list
108-
- [ ] get_created_content_list
109-
- [ ] update_setting
110-
- [x] Miscs
111-
- [x] get_tags
112-
- [ ] get_captcha
113-
- [ ] sign_up
114-
115-
Others
116-
117-
- [ ] asyncLuoguAPI
118-
- [ ] staticLuoguAPI
104+
API Implementation Status
105+
106+
### Core APIs
107+
108+
- [x] Problem API
109+
- [x] get_problem_list
110+
- [x] get_team_problem_list
111+
- [x] get_problem
112+
- [x] get_problem_settings
113+
- [x] update_problem_settings
114+
- [x] update_testcases_settings
115+
- [x] create_problem
116+
- [x] delete_problem
117+
- [x] transfer_problem
118+
- [ ] download_testcases
119+
- [ ] upload_testcases
120+
121+
- [x] User API
122+
- [x] get_user
123+
- [x] get_user_info
124+
- [x] get_user_followings_list
125+
- [x] get_user_followers_list
126+
- [x] get_user_blacklist
127+
- [x] search_user
128+
129+
- [-] User Operations
130+
- [ ] login
131+
- [ ] logout
132+
- [x] me
133+
- [ ] submit_code
134+
- [x] get_created_problem_list
135+
- [ ] get_created_problemset_list
136+
- [ ] get_created_content_list
137+
- [ ] update_setting
138+
139+
- [-] Miscellaneous
140+
- [x] get_tags
141+
- [ ] get_captcha
142+
- [ ] sign_up
143+
144+
### Alternative API Implementations
145+
146+
- [x] asyncLuoguAPI (Experimental)
147+
- [x] Async versions of all implemented core APIs
148+
- [ ] Performance optimizations
149+
- [ ] Comprehensive error handling
150+
151+
- [ ] staticLuoguAPI
152+
- [ ] Initial implementation
153+
- [ ] Documentation
154+
155+
### Test Cases and Documentation
156+
157+
Note: Test suite and documentation are planned for implementation after API features are stabilized. This includes:
158+
159+
- Comprehensive test coverage for both sync and async APIs
160+
- API reference documentation with examples
161+
- Integration test scenarios
162+
- Development guides and best practices
163+
164+
These will be prioritized once the core functionality reaches a stable state.

examples/readme_example_async.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
import pyLuogu
3+
4+
# Initialize the async API without cookies
5+
luogu = pyLuogu.asyncLuoguAPI()
6+
7+
async def main():
8+
async with luogu:
9+
problems = (await luogu.get_problem_list()).problems
10+
for problem in problems:
11+
print(problem.title)
12+
13+
asyncio.run(main())
File renamed without changes.

pyLuogu/async_api.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,10 @@ async def upload_testcases(
373373

374374
async def get_user(self, uid: int) -> UserDataRequestResponse:
375375
res = await self._send_request(endpoint=f"user/{uid}")
376-
377376
return UserDataRequestResponse(res)
378377

379378
async def get_user_info(self, uid: int) -> UserDetails:
380379
res = await self._send_request(endpoint=f"api/user/info/{uid}")
381-
382380
return UserDetails(res["user"])
383381

384382
async def get_user_following_list(self, uid: int, page: int | None = None) -> List[UserDetails]:
@@ -398,7 +396,6 @@ async def get_user_blacklist(self, uid: int, page: int | None = None) -> List[Us
398396

399397
async def search_user(self, keyword: str) -> List[UserSummary]:
400398
params = UserSearchRequestParams({"keyword" : keyword})
401-
402399
res = await self._send_request(endpoint="api/user/search", params=params)
403400
return [UserSummary(user) for user in res["users"]]
404401

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "luogu-api-python"
7-
version = "0.0.2-rc"
7+
version = "0.0.2"
88
description = "A Python library to interact with the Luogu online judge system"
99
readme = "README.md"
1010
authors = [

0 commit comments

Comments
 (0)