Skip to content

Commit d9c92bb

Browse files
committed
lang thing
1 parent 377c4ea commit d9c92bb

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

scripts/sync_config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,25 @@
3131

3232
COMMENT_CONFIG_REGEX = re.compile(r"<COMMENT>")
3333

34+
EXISTING_LANGUAGE_REGEX = re.compile(r"^lang = \"(\w+)\"$", re.MULTILINE)
3435

35-
def main(language: str = "rust") -> None:
36+
37+
def main(language: str) -> None:
3638
cj = browser_cookie3.chrome(domain_name=LEETCODE_DOMAIN_NAME)
3739
cookies = {c.name: c.value for c in cj}
3840

3941
csrftoken = cookies[CSRFTOKEN_KEY]
4042
leetcode_session = cookies[LEETCODE_SESSION_KEY]
4143

44+
with open(INITIAL_CONFIG_LOCATION, "r") as f:
45+
content = f.read()
46+
47+
# If the language isn't provided, take the language from the current config
48+
if language is None and os.path.exists(TARGET_CONFIG_LOCATION):
49+
with open(TARGET_CONFIG_LOCATION) as f:
50+
if match := re.search(EXISTING_LANGUAGE_REGEX, f.read()):
51+
language = match.groups()[0]
52+
4253
language_stubs = []
4354
if os.path.exists(f"{STUBS_LOCATION}/{language}.txt"):
4455
language_stubs = [

0 commit comments

Comments
 (0)