Last active
November 4, 2021 14:43
-
-
Save alexandru-dinu/6e6a42c1a44bcbd68084625ebf3769d9 to your computer and use it in GitHub Desktop.
Get the most recent accepted submissions from leetcode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
1) Fetch submisssions using | |
https://github.com/world177/Leetcode-Downloader-for-Submissions | |
2) Use this script to move the *latest accepted* submission to ./out/<problem> | |
3) Replace "// " comments from the first line of all python files | |
f in $(ls **/*.py); do sed -i.bak "1 s/\/\/ /# /" $f; done | |
""" | |
import shutil | |
from pathlib import Path | |
from datetime import datetime | |
datetime_fmt = r"%m-%d-%Y, %I:%M:%S %p" | |
out = Path("./out") | |
out.mkdir(parents=True, exist_ok=True) | |
for d in Path("leetcode").iterdir(): | |
if not (d / "Accepted").exists(): | |
print(f"No accepted solutions for {d.name}! Skipping...") | |
continue | |
latest = max( | |
(d / "Accepted").iterdir(), | |
key=lambda f: datetime.strptime(f.name, datetime_fmt), | |
) | |
sol = [f for f in latest.iterdir() if f.suffix != ".txt"] | |
assert len(sol) == 1, sol | |
src = sol[0] | |
dst = (out / d.name.replace("-", "_")).with_suffix(src.suffix) | |
shutil.copy(src, dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment