Skip to content

Commit

Permalink
Updating method to make use of cloning instead of submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
Zanger67 committed Jul 27, 2024
1 parent bc7383b commit 426b2a3
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 50 deletions.
22 changes: 12 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
48 changes: 36 additions & 12 deletions main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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'<!-- This readme was generated using [WikiLeet](<https://github.com/Zanger67/WikiLeet>) -->')\n",
" file.write(f'> My LeetCode Profile: [{username}](https://leetcode.com/u/{username}/)\\n')\n",
" \n",
" # if difficultyBasedMarkdowns :\n",
Expand Down Expand Up @@ -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",
Expand Down
48 changes: 36 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down Expand Up @@ -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()
Expand All @@ -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) :
Expand Down Expand Up @@ -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 = }')
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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'<!-- This readme was generated using [WikiLeet](<https://github.com/Zanger67/WikiLeet>) -->')
file.write(f'> My LeetCode Profile: [{username}](https://leetcode.com/u/{username}/)\n')

# if difficultyBasedMarkdowns :
Expand Down Expand Up @@ -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}>)']

Expand Down
Binary file removed misc/pat_setup_images/image-10.png
Binary file not shown.
Binary file removed misc/pat_setup_images/image-11.png
Binary file not shown.
Binary file removed misc/pat_setup_images/image-5.png
Binary file not shown.
Binary file removed misc/pat_setup_images/image-7.png
Binary file not shown.
Binary file removed misc/pat_setup_images/image-8.png
Binary file not shown.
Binary file removed misc/pat_setup_images/image-9.png
Binary file not shown.
Binary file removed misc/pat_setup_images/image.png
Binary file not shown.
16 changes: 0 additions & 16 deletions pat_setup.md

This file was deleted.

0 comments on commit 426b2a3

Please sign in to comment.