Skip to content

Use python-leetcode #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Retrieve more question metadata & polish front-end connections
  • Loading branch information
seanprashad committed Aug 6, 2022
commit 1fd8122d899d0949cd40cef74c5ba906b149944e
14 changes: 11 additions & 3 deletions cron/update_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime

LEETCODE_SESSION_TOKEN = os.environ.get("LEETCODE_SESSION_TOKEN")

questions_file = os.getcwd() + "/src/data/questions.json"

print("=== Reading questions file ===")
Expand Down Expand Up @@ -32,37 +33,44 @@

api_instance = leetcode.DefaultApi(leetcode.ApiClient(configuration))

for question in questions["data"]:
for question in questions["data"]:
graphql_request = leetcode.GraphqlQuery(
query='''query questionData($titleSlug: String!) {
question(titleSlug: $titleSlug) {
title
difficulty
companyTagStats
isPaidOnly
}
}
''',
variables=leetcode.GraphqlQueryGetQuestionDetailVariables(
title_slug=question["url"])
title_slug=question["slug"])
)

response = api_instance.graphql_post(body=graphql_request).to_dict()

leetcode_title = response["data"]["question"]["title"]
leetcode_difficulty = response["data"]["question"]["difficulty"]
leetcode_companies = json.loads(
response["data"]["question"]["company_tag_stats"])["1"]
leetcode_premium = response["data"]["question"]["is_paid_only"]

companies = []

for leetcode_company in leetcode_companies:
company = {
"name": leetcode_company["slug"],
"name": leetcode_company["name"],
"slug": leetcode_company["slug"],
"frequency": leetcode_company["timesEncountered"]
}

companies.append(company)

question["title"] = leetcode_title
question["difficulty"] = leetcode_difficulty
question["companies"] = companies
question["premium"] = leetcode_premium

print("=== Finished checking all questions ===")

Expand Down
25 changes: 13 additions & 12 deletions src/components/Table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ const Table = () => {
return (
<NavLink
target="_blank"
href={`https://leetcode.com/problems/${cellInfo.row.original.url}/`}
href={`https://leetcode.com/problems/${cellInfo.row.original.slug}/`}
onClick={() => {
Event(
'Table',
'Clicked question url',
`${cellInfo.row.original.name} question url`,
'Clicked question title',
`${cellInfo.row.original.title} question title`,
);
}}
>
Expand All @@ -255,7 +255,7 @@ const Table = () => {
) : (
''
)}
{cellInfo.row.original.name}
{cellInfo.row.original.title}
</NavLink>
);
},
Expand All @@ -266,7 +266,7 @@ const Table = () => {
accessor: 'solutions',
disableSortBy: true,
Cell: cellInfo => {
const url = `https://leetcode.com/problems/${cellInfo.row.original.url}/`;
const url = `https://leetcode.com/problems/${cellInfo.row.original.slug}/`;
return (
<NavLink
target="_blank"
Expand All @@ -275,7 +275,7 @@ const Table = () => {
Event(
'Table',
'Clicked solution',
`${cellInfo.row.original.name} solution`,
`${cellInfo.row.original.slug} solution`,
);
}}
>
Expand Down Expand Up @@ -366,7 +366,7 @@ const Table = () => {
>
Companies{' '}
<span
data-tip={`Companies retrieved from Leetcode Premium on ${month} ${day}, ${year}`}
data-tip={`Companies retrieved from Leetcode Premium on ${month} ${day}, ${year} - thanks to @leo-step!`}
>
<FaQuestionCircle />
</span>
Expand All @@ -384,14 +384,15 @@ const Table = () => {
: -1;
},
Cell: cellInfo => {
const questionSlug = cellInfo.row.original.slug;
const companies = cellInfo.row.original.companies.map(company => {
const infoText = `${company} (${company.frequency})`;
const tooltipText = `Asked by ${company.name} ${company.frequency} times`;
return (
<img
key={company.name}
src={`${iconPath}${company.name}.png`}
alt={infoText}
data-tip={infoText}
key={`${questionSlug}-${company.name}`}
src={`${iconPath}${company.slug}.png`}
alt={company.name}
data-tip={tooltipText}
/>
);
});
Expand Down
Loading