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

Commit 6593519

Browse files
GraphQL Cron Job (#182)
* try running python script * try to fix yml syntax error * attempt 3 * run difficulty update script
1 parent 53a7758 commit 6593519

File tree

4 files changed

+2304
-0
lines changed

4 files changed

+2304
-0
lines changed

‎.github/workflows/run-python.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: run-python
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: actions/setup-python@v4
11+
with:
12+
python-version: '3.x'
13+
architecture: 'x64'
14+
- run: |
15+
python -m pip install --upgrade pip
16+
pip install requests
17+
- run: |
18+
python cron/difficulty.py

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
npm-debug.log*
2323
yarn-debug.log*
2424
yarn-error.log*
25+
26+
__pycache__

‎cron/difficulty.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import requests
2+
from urllib.parse import urlparse
3+
from questions import questions
4+
5+
query = '''query questionData($titleSlug: String!) {
6+
question(titleSlug: $titleSlug) {
7+
difficulty
8+
}
9+
}
10+
'''
11+
12+
for question in questions:
13+
p = urlparse(question["url"])
14+
title_slug = p.path.rstrip('/').split('/')[-1]
15+
our_difficulty = question["difficulty"]
16+
variables = {"titleSlug": title_slug}
17+
18+
response = requests.post("https://leetcode.com/graphql",
19+
json={"query": query, "variables": variables}
20+
)
21+
22+
their_difficulty = response.json()["data"]["question"]["difficulty"]
23+
24+
if their_difficulty != our_difficulty:
25+
print(f'{question["name"]}: {our_difficulty} -> {their_difficulty}')
26+
27+
print("Finished checking all questions")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /