MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / Leetcode

Class Leetcode

src/leetcode.py:25–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 return False
24
25class Leetcode:
26 def __init__(self):
27 self.dict = self.init_db()
28 self.finished = []
29 self.flasks = []
30 # read user
31 p = util.get_root("user", "leetcode")
32 entries = os.listdir(p)
33 for k in entries:
34 if k.endswith(".cpp") or k.endswith(".py"):
35 self.finished.append(k)
36 elif k.endswith(".md"):
37 self.flasks.append(k)
38
39 def init_db(self):
40 d = SqliteDict(util.get_db('leetcode.sqlite'), autocommit=True)
41 return d
42
43 def close_db(self):
44 self.dict.close()
45
46 def get_tag_problems(self, tag):
47 problems = self.get_all_problems()
48 datas = []
49 for k in problems:
50 try:
51 j = json.loads(problems[k])
52 tags = j['data']['question']['topicTags']
53 paid_only = j['data']['question']['paid_only']
54 if len(tags) > 0:
55 for t in tags:
56 if t['slug'] == tag and paid_only == False:
57 datas.append(j)
58 break
59 except Exception as e:
60 print("unknow key:", k, e)
61 pass
62 return datas
63
64 def get_all_problems(self):
65 d = {}
66 for k, v in self.dict.iteritems():
67 if k.startswith("leetcode_") and k[9].isdigit():
68 d[k] = v
69 return d
70
71 def save_problem(self, id, content):
72 self.dict[leetcode_key(id)] = content
73 self.dict.commit()
74
75 def get_problem_content(self, id):
76 v = self.dict.get(leetcode_key(id))
77 return v
78
79 def get_level(self, id):
80 content = self.get_problem_content(id)
81 if content == None:
82 print("title not exist:", id)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected