-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_.printDaily.py
executable file
·85 lines (76 loc) · 1.99 KB
/
_.printDaily.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
import requests
import json
endpoint = 'https://leetcode.com/graphql'
query = """query getDailyChallenge {
activeDailyCodingChallengeQuestion {
date
link
question {
questionId
title
titleSlug
difficulty
categoryTitle
likes
dislikes
topicTags {
name
}
hints
similarQuestionList {
questionId
title
titleSlug
difficulty
categoryTitle
topicTags{
name
}
}
}
}
}"""
GR = '\033[92m'
YL = '\033[93m'
MG = '\033[95m'
CY = '\033[96m'
RE = '\033[0m'
def printDaily():
payload = { 'query': query }
resp = requests.post( endpoint, json=payload )
if resp.status_code != 200:
print('/err', resp.status_code)
return
D = json.loads(resp.text)['data']['activeDailyCodingChallengeQuestion']['question']
qid = D['questionId']
name, nameslug = D['title'], D['titleSlug']
typ_, diff = D['categoryTitle'], D['difficulty']
love, hate = D['likes'], D['dislikes']
tops = ', '.join([_['name'] for _ in D['topicTags']])
sqList = [ _ for _ in D['similarQuestionList']]
Name = f'{qid} - {GR}{name}{RE}'
Typ_ = f'Type: {typ_}'
Diff = f'Rank: {diff}'
Like = f'Love: {love}✓ {hate}✖'
Tops = f'Tags: {tops}'
Hints = '\n\n'.join([ f'{i}: {_}' for i,_ in enumerate( D['hints']) ])
print(f'{YL}Daily question{RE}\n')
print(Name)
print(Diff)
print(Tops)
print(Typ_)
print(Like,'\n')
print(Hints) if Hints else print('no hints')
print()
if not sqList:
print('no similar problems')
else:
for i, sq in enumerate(sqList):
print(f'{YL}Similar question{RE} {i + 1}\n')
print( f'{sq['questionId']} - {GR}{sq['title']}{RE}' )
tops = ', '.join([_['name'] for _ in sq ['topicTags']])
print( f'Tags: {tops}' )
print( f'Rank: {sq['difficulty']}' )
print()
printDaily()