Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0911d7

Browse files
committed
Add searching user stats
1 parentba800ed commitd0911d7

File tree

7 files changed

+227
-148
lines changed

7 files changed

+227
-148
lines changed

‎README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ leetcoderustapi = "0.1.7"
1717
###Authentication
1818
To use the LeetCode API, you need to obtain an authentication token. Follow the instructions provided by LeetCode to obtain your token.
1919

20-
###Example:Actions with problems
20+
###Example:Action with problems
2121
```rust
22-
useleetcoderustapi::UserApi;
22+
useleetcoderustapi::{problem_build::{Tags,Category,Difficulty,Status},UserApi};
2323

2424
#[tokio::main]
2525
asyncfnmain() {
@@ -35,16 +35,16 @@ async fn main() {
3535
// Find problems by properties with creating problem builder
3636
letproblems_builder=api
3737
.problem_builder()
38-
.set_category(leetcoderustapi::Category::Algorithms)
39-
.set_difficulty(leetcoderustapi::Difficulty::Easy)
38+
.set_category(Category::Algorithms)
39+
.set_difficulty(Difficulty::Easy)
4040
.set_keyword("sum")
4141
//max show notes limit is 2763; default is 5
4242
.set_note_limit(3)
43-
.set_status(leetcoderustapi::Status::Solved)
43+
.set_status(Status::Solved)
4444
//max tags over 50+
4545
.set_tags(vec![
46-
leetcoderustapi::Tags::Array,
47-
leetcoderustapi::Tags::BinarySearch,
46+
Tags::Array,
47+
Tags::BinarySearch,
4848
])
4949
.build()
5050
.await
@@ -96,10 +96,15 @@ async fn main() {
9696
.send_test("rust","impl Solution { fn two_sum() {}}")
9797
.await
9898
.unwrap();
99+
100+
// And we can check public stats of the searched profile
101+
letpublic_user_data=api.search_public_user("1101-1").await.unwrap();
102+
103+
99104
}
100105
```
101106

102-
###Example: Actions withUser profile
107+
###Example: Actions withSelf profile
103108
```rust
104109
#[tokio::main]
105110
asyncfnmain() {
@@ -131,10 +136,10 @@ async fn main() {
131136
user_profile.set_private("hard_problems").await.unwrap();
132137

133138
// Get link to the list if it is a public
134-
user_profile.get_share_url("hard_problems").await.unwrap();
139+
letshare_list_url=user_profile.get_share_url("hard_problems").await.unwrap();
135140

136141
// Show existing lists
137-
user_profile.show_lists();
142+
letlists=user_profile.show_lists();
138143

139144
// Delete list with provided name
140145
user_profile
@@ -143,7 +148,7 @@ async fn main() {
143148
.unwrap();
144149

145150
// Show users last 10 notification
146-
user_profile.get_notifications().await.unwrap();
151+
letnotifications=user_profile.get_notifications().await.unwrap();
147152
}
148153
```
149154

‎src/lib.rs

Lines changed: 23 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use error::Errors;
22
use problem_actions::Problem;
33
use problem_build::{Filters,ProblemBuilder};
4-
use profile::{MyProfile,UserProfile};
4+
use profile::MyProfile;
55
use reqwest::header::{HeaderMap,HeaderValue};
66
use resources::{
77
cookie::CookieData, descr::ProblemData, fav_list::FavoriteList,
8-
problemfulldata::ProblemFullData,
8+
problemfulldata::ProblemFullData, pub_data_profile::UserFoundData,
99
};
1010
use serde_json::{json,Value};
1111

@@ -230,8 +230,27 @@ impl UserApi {
230230
})
231231
}
232232

233-
pubasyncfnfind_user(&self,username:&str) ->UserProfile{
234-
todo!()
233+
pubasyncfnsearch_public_user(&self,profile_name:&str) ->Result<UserFoundData,Errors>{
234+
let query =json!({
235+
"query":"query userPublicProfile($username: String!) {\n matchedUser(username: $username) {\n contestBadge {\n name\n expired\n hoverText\n icon\n }\n username\n githubUrl\n twitterUrl\n linkedinUrl\n profile {\n ranking\n userAvatar\n realName\n aboutMe\n school\n websites\n countryName\n company\n jobTitle\n skillTags\n postViewCount\n postViewCountDiff\n reputation\n reputationDiff\n solutionCount\n solutionCountDiff\n categoryDiscussCount\n categoryDiscussCountDiff\n }\n }\n}",
236+
"variables":{
237+
"username": profile_name
238+
},
239+
"operationName":"userPublicProfile"
240+
});
241+
242+
let query = serde_json::to_string(&query).unwrap();
243+
244+
let data_info =self
245+
.client
246+
.post("https://leetcode.com/graphql/")
247+
.body(query)
248+
.send()
249+
.await?
250+
.text()
251+
.await?;
252+
253+
Ok(serde_json::from_str::<UserFoundData>(&data_info)?)
235254
}
236255

237256
asyncfnfetch_fav_list_data(&self) ->Result<FavoriteList,Errors>{
@@ -297,105 +316,3 @@ impl UserApi {
297316
Ok(serde_json::from_str::<FavoriteList>(&list_data)?)
298317
}
299318
}
300-
301-
#[derive(Debug)]
302-
#[allow(unused)]
303-
pubenumCategory{
304-
AllTopics,
305-
Algorithms,
306-
DataBase,
307-
JavaScript,
308-
Shell,
309-
Concurrency,
310-
}
311-
312-
#[derive(Debug)]
313-
#[allow(unused)]
314-
pubenumDifficulty{
315-
Easy,
316-
Medium,
317-
Hard,
318-
}
319-
320-
#[derive(Debug)]
321-
#[allow(unused)]
322-
pubenumStatus{
323-
Todo,
324-
Solved,
325-
Attempted,
326-
}
327-
#[allow(unused)]
328-
#[derive(Debug)]
329-
pubenumTags{
330-
Array,
331-
String,
332-
HashTable,
333-
Math,
334-
DynamicProgramming,
335-
Sorting,
336-
Greedy,
337-
DepthFirstSearch,
338-
Database,
339-
BinarySearch,
340-
BreadthFirstSearch,
341-
Tree,
342-
Matrix,
343-
TwoPointers,
344-
BinaryTree,
345-
BitManipulation,
346-
HeapPriorityQueue,
347-
Stack,
348-
Graph,
349-
PrefixSum,
350-
Simulation,
351-
Design,
352-
Counting,
353-
Backtracking,
354-
SlidingWindow,
355-
UnionFind,
356-
LinkedList,
357-
OrderedSet,
358-
MonotonicStack,
359-
Enumeration,
360-
Recursion,
361-
Trie,
362-
DivideAndConquer,
363-
Bitmask,
364-
BinarySearchTree,
365-
NumberTheory,
366-
Queue,
367-
SegmentTree,
368-
Memoization,
369-
Geometry,
370-
TopologicalSort,
371-
BinaryIndexedTree,
372-
HashFunction,
373-
GameTheory,
374-
ShortestPath,
375-
Combinatorics,
376-
DataStream,
377-
Interactive,
378-
StringMatching,
379-
RollingHash,
380-
Brainteaser,
381-
Randomized,
382-
MonotonicQueue,
383-
MergeSort,
384-
Iterator,
385-
Concurrency,
386-
DoublyLinkedList,
387-
ProbabilityStatistics,
388-
Quickselect,
389-
BucketSort,
390-
SuffixArray,
391-
MinimumSpanningTree,
392-
CountingSort,
393-
Shell,
394-
LineSweep,
395-
ReservoirSampling,
396-
EulerianCircuit,
397-
RadixSort,
398-
StronglyConnectedComponent,
399-
RejectionSampling,
400-
BiconnectedComponent,
401-
}

‎src/problem_build.rs

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::Deserialize;
22
use serde_json::json;
33

4-
usecrate::{error::Errors, resources::descr::ProblemData,Category,Difficulty,Status,Tags};
4+
usecrate::{error::Errors, resources::descr::ProblemData};
55

66
#[derive(Debug)]
77
pubstructProblemBuilder{
@@ -238,3 +238,105 @@ impl ProblemBuilder {
238238
Ok(serde_json::from_str::<ProblemData>(&problem_info)?)
239239
}
240240
}
241+
242+
#[derive(Debug)]
243+
#[allow(unused)]
244+
pubenumCategory{
245+
AllTopics,
246+
Algorithms,
247+
DataBase,
248+
JavaScript,
249+
Shell,
250+
Concurrency,
251+
}
252+
253+
#[derive(Debug)]
254+
#[allow(unused)]
255+
pubenumDifficulty{
256+
Easy,
257+
Medium,
258+
Hard,
259+
}
260+
261+
#[derive(Debug)]
262+
#[allow(unused)]
263+
pubenumStatus{
264+
Todo,
265+
Solved,
266+
Attempted,
267+
}
268+
#[allow(unused)]
269+
#[derive(Debug)]
270+
pubenumTags{
271+
Array,
272+
String,
273+
HashTable,
274+
Math,
275+
DynamicProgramming,
276+
Sorting,
277+
Greedy,
278+
DepthFirstSearch,
279+
Database,
280+
BinarySearch,
281+
BreadthFirstSearch,
282+
Tree,
283+
Matrix,
284+
TwoPointers,
285+
BinaryTree,
286+
BitManipulation,
287+
HeapPriorityQueue,
288+
Stack,
289+
Graph,
290+
PrefixSum,
291+
Simulation,
292+
Design,
293+
Counting,
294+
Backtracking,
295+
SlidingWindow,
296+
UnionFind,
297+
LinkedList,
298+
OrderedSet,
299+
MonotonicStack,
300+
Enumeration,
301+
Recursion,
302+
Trie,
303+
DivideAndConquer,
304+
Bitmask,
305+
BinarySearchTree,
306+
NumberTheory,
307+
Queue,
308+
SegmentTree,
309+
Memoization,
310+
Geometry,
311+
TopologicalSort,
312+
BinaryIndexedTree,
313+
HashFunction,
314+
GameTheory,
315+
ShortestPath,
316+
Combinatorics,
317+
DataStream,
318+
Interactive,
319+
StringMatching,
320+
RollingHash,
321+
Brainteaser,
322+
Randomized,
323+
MonotonicQueue,
324+
MergeSort,
325+
Iterator,
326+
Concurrency,
327+
DoublyLinkedList,
328+
ProbabilityStatistics,
329+
Quickselect,
330+
BucketSort,
331+
SuffixArray,
332+
MinimumSpanningTree,
333+
CountingSort,
334+
Shell,
335+
LineSweep,
336+
ReservoirSampling,
337+
EulerianCircuit,
338+
RadixSort,
339+
StronglyConnectedComponent,
340+
RejectionSampling,
341+
BiconnectedComponent,
342+
}

‎src/profile.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use serde_json::json;
22

33
usecrate::{
44
error::Errors,
5-
resources::{fav_list::FavoriteList, notification::NotificationsData, data_profile::ProfileData},
5+
resources::{
6+
data_profile::ProfileData, fav_list::FavoriteList, notification::NotificationsData,
7+
},
68
};
79

810
#[derive(Debug)]
@@ -191,7 +193,7 @@ impl MyProfile {
191193
Ok(serde_json::from_str::<NotificationsData>(&problem_info)?)
192194
}
193195

194-
pubasyncfnprofile_data(&self) ->Result<ProfileData,Errors>{
196+
pubasyncfnprofile_info(&self) ->Result<ProfileData,Errors>{
195197
let query =r#"
196198
query globalData {
197199
userStatus {
@@ -227,7 +229,8 @@ impl MyProfile {
227229

228230
let query = serde_json::to_string(&json_data).unwrap();
229231

230-
let data_info =self.client
232+
let data_info =self
233+
.client
231234
.post("https://leetcode.com/graphql/")
232235
.body(query)
233236
.send()
@@ -236,12 +239,5 @@ impl MyProfile {
236239
.await?;
237240

238241
Ok(serde_json::from_str::<ProfileData>(&data_info)?)
239-
240242
}
241243
}
242-
243-
pubstructUserProfile{
244-
pubclient: reqwest::Client,
245-
}
246-
247-
pubstructUserFullData{}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp