diff --git a/action.yml b/action.yml index e6e70ac..e197c2e 100644 --- a/action.yml +++ b/action.yml @@ -32,16 +32,18 @@ runs: - name: Pull current version of markdown generator | Cloning if not present shell: bash run: | - if [ -d .readme_updater/ ]; then - echo "Submodule exists." - else - echo "Submodule not found. Adding..." - git submodule add https://github.com/Zanger67/Leetcode-Progress-Tracker.git '.readme_updater' - fi + git clone --recurse-submodules https://github.com/Zanger67/Leetcode-Progress-Tracker.git '.readme_updater' + + # if [ -d .readme_updater/ ]; then + # echo "Submodule exists." + # else + # echo "Submodule not found. Adding..." + # git submodule add https://github.com/Zanger67/Leetcode-Progress-Tracker.git '.readme_updater' + # fi - echo "Initializing and updating submodules..." - git submodule update --init --recursive - git submodule update --recursive --remote + # echo "Initializing and updating submodules..." + # git submodule update --init --recursive + # git submodule update --recursive --remote # cd .readme_updater @@ -109,7 +111,7 @@ runs: run: | git config --global user.name "Zanger67/leetcode" git config --global user.email "Zanger67[bot]@Zanger67.github.io" - git add . + git add -- . ':!.readme_updater' git commit -m 'Updated markdown files' || exit 0 git push diff --git a/main.ipynb b/main.ipynb index 7769328..493d85e 100644 --- a/main.ipynb +++ b/main.ipynb @@ -235,17 +235,22 @@ " result = process.stdout.readlines()\n", " modifiedTimes = []\n", " \n", - " if len(result) >= 1:\n", - " for line in result:\n", - " modifiedTimes.append(line.decode(\"utf-8\").replace('\\n', ''))\n", + " for line in result:\n", + " temp = line.decode(\"utf-8\").replace('\\n', '')\n", " \n", - " # In case of a redundant '\\n' at the end of an output\n", - " if modifiedTimes[-1] == '':\n", - " modifiedTimes.pop()\n", + " # In case of a redundant '\\n' at the end of an output\n", + " if temp :\n", + " modifiedTimes.append(temp)\n", + " \n", + " # Debugging\n", + " if '1404' in cmd[-1] :\n", + " print(f'{cmd = }')\n", + " print(f'{modifiedTimes = }')\n", + " print(f'{result = }')\n", " \n", " try :\n", - " creationDate = datetime.strptime(time.ctime(int(modifiedTimes[0])), '%a %b %d %H:%M:%S %Y')\n", - " modifiedDate = datetime.strptime(time.ctime(int(modifiedTimes[-1])), '%a %b %d %H:%M:%S %Y')\n", + " creationDate = datetime.strptime(time.ctime(int(min(modifiedTimes))), '%a %b %d %H:%M:%S %Y')\n", + " modifiedDate = datetime.strptime(time.ctime(int(max(modifiedTimes))), '%a %b %d %H:%M:%S %Y')\n", " \n", " except ValueError as ve:\n", " print(f'Error in parsing {path}')\n", @@ -280,7 +285,9 @@ " chdir('../')\n", " print(f'README path: {getcwd() = }')\n", "\n", - " cmd = r\"git log --follow --format=%ct --reverse --\".split()\n", + " cmd = r\"git log -M --format=%ct --reverse --\".split()\n", + " # cmd = r\"git log -M --follow --format=%ct --reverse --\".split()\n", + " # cmd = r\"git log --follow --format=%ct --reverse --\".split()\n", " output = {}\n", " \n", " oldest_date = datetime.now()\n", @@ -304,6 +311,8 @@ " \n", " # print((15 - pqBarsPrinted) * '=', '\\n\\n')\n", " # else :\n", + " \n", + " \n", " with tqdm(total=len(paths)) as pbar :\n", " # with tqdm(total=len(paths), position=0, leave=True) as pbar :\n", " for i, path in enumerate(paths) :\n", @@ -785,6 +794,7 @@ " if qNo in questionData and questionData[qNo]['date_done'] <= date + timedelta(days=1, hours=12) :\n", " dailiesDict[date] = questionData[qNo].copy()\n", " dailiesDict[date]['date_done'] = date\n", + " questionData[qNo]['categories'].add('Daily')\n", " # print(f'{dailiesDict[date] = }')\n", "\n", " # print(f'{dailiesDict = }')\n", @@ -817,6 +827,7 @@ " if qNo in questionData and questionData[qNo]['date_done'] <= date + timedelta(days=8) :\n", " weekliesDict[date] = questionData[qNo].copy()\n", " weekliesDict[date]['date_done'] = date\n", + " questionData[qNo]['categories'].add('Weekly Premium')\n", "\n", " return weekliesDict" ] @@ -1648,7 +1659,8 @@ " *,\n", " code_length: bool = False,\n", " recent: bool = False,\n", - " daily: bool = False) -> str : # output path\n", + " daily: bool = False,\n", + " weekly: bool = False) -> str : # output path\n", " \n", " df = None\n", " fileName = None\n", @@ -1681,6 +1693,16 @@ " details = 'Dates are for the date I completed the ' + \\\n", " 'question so due to the my time zone and how it lines up with ' + \\\n", " 'UTC, it may be off by a day.\\n\\n'\n", + " elif weekly :\n", + " weeklyQuestionData = parseQuestionsForWeeklies(questionData)\n", + " \n", + " df = byRecentQuestionDataDataframe(weeklyQuestionData)\n", + " fileName = 'Weekly_Questions.md'\n", + " # header_data = f'# [Daily Questions](<{DAILY_URL}>)\\n\\n'\n", + " header_data = f'# Weekly Premium Questions\\n\\n'\n", + " details = 'Dates are for the date I completed the ' + \\\n", + " 'question so due to the my time zone and how it lines up with ' + \\\n", + " 'UTC, it may be off by a day.\\n\\n'\n", " else :\n", " print('Error. No markdown generation specified.')\n", " print()\n", @@ -1744,7 +1766,7 @@ " with open(readmePath, 'w') as file :\n", " username = getenv('LEETCODE_USERNAME')\n", " file.write(f'# **[LeetCode Records](https://leetcode.com/u/{username}/)** ({qSolvedHeader})\\n\\n')\n", - " \n", + " file.write(f'')\n", " file.write(f'> My LeetCode Profile: [{username}](https://leetcode.com/u/{username}/)\\n')\n", " \n", " # if difficultyBasedMarkdowns :\n", @@ -1879,10 +1901,12 @@ " # written for the question\n", " # code_length_md_path = exportCodeLengthMarkdown(questionData)\n", " print('Generating category lists...')\n", + " dailyQuestions = miscMarkdownGenerations(questionData, daily=True)\n", + " weeklyQuestions = miscMarkdownGenerations(questionData, weekly=True)\n", " byCodeLength = miscMarkdownGenerations(questionData, code_length=True)\n", " byRecentlySolved = miscMarkdownGenerations(questionData, recent=True)\n", - " dailyQuestions = miscMarkdownGenerations(questionData, daily=True)\n", " altSorts = [f'- [Daily Questions](<{dailyQuestions}>)',\n", + " f'- [Weekly Questions](<{weeklyQuestions}>)',\n", " f'- [Questions By Code Length](<{byCodeLength}>)',\n", " f'- [Questions By Recent](<{byRecentlySolved}>)']\n", " \n", diff --git a/main.py b/main.py index d0da901..5eb736a 100644 --- a/main.py +++ b/main.py @@ -170,17 +170,22 @@ def individualCTimeViaGit(cmd: List[str]) -> Tuple[datetime, datetime] : result = process.stdout.readlines() modifiedTimes = [] - if len(result) >= 1: - for line in result: - modifiedTimes.append(line.decode("utf-8").replace('\n', '')) + for line in result: + temp = line.decode("utf-8").replace('\n', '') - # In case of a redundant '\n' at the end of an output - if modifiedTimes[-1] == '': - modifiedTimes.pop() + # In case of a redundant '\n' at the end of an output + if temp : + modifiedTimes.append(temp) + + # Debugging + if '1404' in cmd[-1] : + print(f'{cmd = }') + print(f'{modifiedTimes = }') + print(f'{result = }') try : - creationDate = datetime.strptime(time.ctime(int(modifiedTimes[0])), '%a %b %d %H:%M:%S %Y') - modifiedDate = datetime.strptime(time.ctime(int(modifiedTimes[-1])), '%a %b %d %H:%M:%S %Y') + creationDate = datetime.strptime(time.ctime(int(min(modifiedTimes))), '%a %b %d %H:%M:%S %Y') + modifiedDate = datetime.strptime(time.ctime(int(max(modifiedTimes))), '%a %b %d %H:%M:%S %Y') except ValueError as ve: print(f'Error in parsing {path}') @@ -212,7 +217,9 @@ def getAllCTimesViaGit(paths: List[str]) -> Dict[str, Tuple[datetime, datetime]] chdir('../') print(f'README path: {getcwd() = }') - cmd = r"git log --follow --format=%ct --reverse --".split() + cmd = r"git log -M --format=%ct --reverse --".split() + # cmd = r"git log -M --follow --format=%ct --reverse --".split() + # cmd = r"git log --follow --format=%ct --reverse --".split() output = {} oldest_date = datetime.now() @@ -236,6 +243,8 @@ def getAllCTimesViaGit(paths: List[str]) -> Dict[str, Tuple[datetime, datetime]] # print((15 - pqBarsPrinted) * '=', '\n\n') # else : + + with tqdm(total=len(paths)) as pbar : # with tqdm(total=len(paths), position=0, leave=True) as pbar : for i, path in enumerate(paths) : @@ -666,6 +675,7 @@ def parseQuestionsForDailies(questionData: dict) -> Dict[int, Question] : if qNo in questionData and questionData[qNo]['date_done'] <= date + timedelta(days=1, hours=12) : dailiesDict[date] = questionData[qNo].copy() dailiesDict[date]['date_done'] = date + questionData[qNo]['categories'].add('Daily') # print(f'{dailiesDict[date] = }') # print(f'{dailiesDict = }') @@ -695,6 +705,7 @@ def parseQuestionsForWeeklies(questionData: dict) -> Dict[int, Question] : if qNo in questionData and questionData[qNo]['date_done'] <= date + timedelta(days=8) : weekliesDict[date] = questionData[qNo].copy() weekliesDict[date]['date_done'] = date + questionData[qNo]['categories'].add('Weekly Premium') return weekliesDict @@ -1401,7 +1412,8 @@ def miscMarkdownGenerations(questionData: dict, *, code_length: bool = False, recent: bool = False, - daily: bool = False) -> str : # output path + daily: bool = False, + weekly: bool = False) -> str : # output path df = None fileName = None @@ -1434,6 +1446,16 @@ def miscMarkdownGenerations(questionData: dict, details = 'Dates are for the date I completed the ' + \ 'question so due to the my time zone and how it lines up with ' + \ 'UTC, it may be off by a day.\n\n' + elif weekly : + weeklyQuestionData = parseQuestionsForWeeklies(questionData) + + df = byRecentQuestionDataDataframe(weeklyQuestionData) + fileName = 'Weekly_Questions.md' + # header_data = f'# [Daily Questions](<{DAILY_URL}>)\n\n' + header_data = f'# Weekly Premium Questions\n\n' + details = 'Dates are for the date I completed the ' + \ + 'question so due to the my time zone and how it lines up with ' + \ + 'UTC, it may be off by a day.\n\n' else : print('Error. No markdown generation specified.') print() @@ -1489,7 +1511,7 @@ def exportPrimaryReadme(dfQuestions: DataFrame, with open(readmePath, 'w') as file : username = getenv('LEETCODE_USERNAME') file.write(f'# **[LeetCode Records](https://leetcode.com/u/{username}/)** ({qSolvedHeader})\n\n') - + file.write(f'') file.write(f'> My LeetCode Profile: [{username}](https://leetcode.com/u/{username}/)\n') # if difficultyBasedMarkdowns : @@ -1621,10 +1643,12 @@ def main(*, recalculateAll: bool = False, noRecord: bool = False) -> None : # written for the question # code_length_md_path = exportCodeLengthMarkdown(questionData) print('Generating category lists...') + dailyQuestions = miscMarkdownGenerations(questionData, daily=True) + weeklyQuestions = miscMarkdownGenerations(questionData, weekly=True) byCodeLength = miscMarkdownGenerations(questionData, code_length=True) byRecentlySolved = miscMarkdownGenerations(questionData, recent=True) - dailyQuestions = miscMarkdownGenerations(questionData, daily=True) altSorts = [f'- [Daily Questions](<{dailyQuestions}>)', + f'- [Weekly Questions](<{weeklyQuestions}>)', f'- [Questions By Code Length](<{byCodeLength}>)', f'- [Questions By Recent](<{byRecentlySolved}>)'] diff --git a/misc/pat_setup_images/image-10.png b/misc/pat_setup_images/image-10.png deleted file mode 100644 index 87f567b..0000000 Binary files a/misc/pat_setup_images/image-10.png and /dev/null differ diff --git a/misc/pat_setup_images/image-11.png b/misc/pat_setup_images/image-11.png deleted file mode 100644 index b94959f..0000000 Binary files a/misc/pat_setup_images/image-11.png and /dev/null differ diff --git a/misc/pat_setup_images/image-5.png b/misc/pat_setup_images/image-5.png deleted file mode 100644 index 82634ee..0000000 Binary files a/misc/pat_setup_images/image-5.png and /dev/null differ diff --git a/misc/pat_setup_images/image-7.png b/misc/pat_setup_images/image-7.png deleted file mode 100644 index 9689459..0000000 Binary files a/misc/pat_setup_images/image-7.png and /dev/null differ diff --git a/misc/pat_setup_images/image-8.png b/misc/pat_setup_images/image-8.png deleted file mode 100644 index 4d78f17..0000000 Binary files a/misc/pat_setup_images/image-8.png and /dev/null differ diff --git a/misc/pat_setup_images/image-9.png b/misc/pat_setup_images/image-9.png deleted file mode 100644 index e2ac1d3..0000000 Binary files a/misc/pat_setup_images/image-9.png and /dev/null differ diff --git a/misc/pat_setup_images/image.png b/misc/pat_setup_images/image.png deleted file mode 100644 index 62c4e73..0000000 Binary files a/misc/pat_setup_images/image.png and /dev/null differ diff --git a/pat_setup.md b/pat_setup.md deleted file mode 100644 index ae504ee..0000000 --- a/pat_setup.md +++ /dev/null @@ -1,16 +0,0 @@ -# How to add your Personal Access Token (PAT) - -A Personal Access Token gives the program permission to read and write into the repository you specify which is neccessary to commit the markdown files. - -`Fine-grained tokens` are access tokens that we can restrict to only allow access to the specific repo you'll be uploading your files, though a general PAT will also function (though not recommended). - -| Setup | Visual | -| :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------- | -| Navigate on github.com to `Settings > Developer Settings > Personal Access Tokens > Fine-Grained Tokens`.

This can be found at [https://github.com/settings/tokens?type=beta](https://github.com/settings/tokens?type=beta) | ![alt text](misc/pat_setup_images/image.png?raw=true) | -| Fill out the form.

Note that the expiration date has a latest date of 1 year from the creation date. | ![alt text](misc/pat_setup_images/image-5.png?raw=true) | -| Select `Only Selected Repositories` and make sure to select the repo you'll be uploading your solutions to.

This makes it the token can only write to this specific repo and no others of your account. | ![alt text](misc/pat_setup_images/image-7.png?raw=true) | -| Give `Access: Read and Write` permission for **`Contents`** then click generate at the bottom. | ![alt text](misc/pat_setup_images/image-8.png?raw=true) | -| Take the newly generated PAT and in your repo, click `Settings > Secrets and Variables > Actions`

This can also be found at:
`https://github.com/[YOUR USERNAME]/[REPO NAME]/settings/secrets/actions` | ![alt text](misc/pat_setup_images/image-9.png?raw=true) ![alt text](misc/pat_setup_images/image-10.png?raw=true) | -| Click `New repository secret` and paste in your token with the name `PAT` | ![alt text](misc/pat_setup_images/image-11.png?raw=true) | - -After that, you should be all set!