leetcode-export icon indicating copy to clipboard operation
leetcode-export copied to clipboard

Solutions downloader

Open garncarz opened this issue 1 year ago • 2 comments

Could you allow also downloading of posted solutions, please?

garncarz avatar Mar 31 '24 19:03 garncarz

It seems this could be done by POSTing to https://leetcode.com/graphql/ userSolutionTopics operation. The query is:

query userSolutionTopics($username: String!, $orderBy: TopicSortingOption, $skip: Int, $first: Int) {
  userSolutionTopics(
    username: $username
    orderBy: $orderBy
    skip: $skip
    first: $first
  ) {
    pageInfo {
      hasNextPage
    }
    edges {
      node {
        id
        title
        url
        viewCount
        questionTitle
        post {
          creationDate
          voteCount
        }
      }
    }
  }
}

The variables are like:

{
  "username": "...",
  "orderBy": "newest_to_oldest",
  "skip": 0,
  "first": 15
}

garncarz avatar Mar 31 '24 21:03 garncarz

Thank you for sharing your suggestion! I had a quick look and found that exporting community solutions would be possible by using the userSolutionTopics graphql api you mentioned as well as the following to actually retrieve the solution:

query communitySolution($topicId: Int!) {
  topic(id: $topicId) {
    id
    viewCount
    topLevelCommentCount
    subscribed
    title
    pinned
    solutionTags {
      name
      slug
    }
    hideFromTrending
    commentCount
    isFavorite
    post {
      id
      voteCount
      voteStatus
      content
      updationDate
      creationDate
      status
      isHidden
      author {
        isDiscussAdmin
        isDiscussStaff
        username
        nameColor
        activeBadge {
          displayName
          icon
        }
        profile {
          userAvatar
          reputation
        }
        isActive
      }
      authorIsModerator
      isOwnPost
    }
  }
}

Right now, I don't have the bandwith to implement this, so I'll keep it unresolved for now. Contributions are welcome!

NeverMendel avatar Apr 03 '24 17:04 NeverMendel