Skip to content

Commit

Permalink
Fixed refresh file
Browse files Browse the repository at this point in the history
Side note: I feel this isn't the best way to handle line terminators in python; I'll try to come up with a better solution later.

Side note 2: I *hate* how line terminators are handled in python...
  • Loading branch information
NeoAdonis committed Dec 5, 2024
1 parent b472a60 commit 2ae5183
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions morning/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 🌅 FUWAMOCO Morning Episode Summaries

Last updated: 2024-11-01 21:56 UTC
Last updated: 2024-12-05 03:26 UTC

| 🗓️ Date | | 📺 Episode | | 📄 Summary | 🔤 Transcript |
| ------ | --- | --------- | --- | --------- | ------------ |
| 2023-07-31 | Mon | [Episode #0](https://youtu.be/Qd7ohtlOOkQ) | pilot episodes always end up a bit different than the planned show, huh! 🐾 | [Summary](summaries/20230731_0.md) | [Transcript](transcripts/20230731/transcript.vtt) |
| 2023-07-31 | Mon | [Episode #0](https://youtu.be/Qd7ohtlOOkQ) | pilot episodes always end up a bit different than the planned show, huh! 🐾 | [Summary](summaries/20230731_0.md) | [Transcript](transcripts/20230731/transcript.vtt) |
| 2023-08-02 | Wed | [Episode #1](https://youtu.be/4giLWiqvyVo) | welcome adventrix! ⚠️ | [Summary](summaries/20230802_1.md) | [Transcript](transcripts/20230802/transcript.vtt) |
| 2023-08-04 | Fri | [Episode #2](https://youtu.be/YILB_0QF-uI) | the start to a new day filled with smiles ✨ | [Summary](summaries/20230804_2.md) | [Transcript](transcripts/20230804/transcript.vtt) |
| 2023-08-07 | Mon | [Episode #3](https://youtu.be/Nph4ogfhuBE) | misunderstanding corner edition❓ | [Summary](summaries/20230807_3.md) | [Transcript](transcripts/20230807/transcript.vtt) |
Expand Down Expand Up @@ -36,7 +36,7 @@ Last updated: 2024-11-01 21:56 UTC
| 2023-10-06 | Fri | [Episode #29](https://youtu.be/Tu6QNPp9d3c) | finally friday (and some secrets) ✨ | [Summary](summaries/20231006_29.md) | [Transcript](transcripts/20231006/transcript.vtt) |
| 2023-10-09 | Mon | [Episode #30](https://youtu.be/4ljeCZkA2mc) | how is it episode 30 already?✨ | [Summary](summaries/20231009_30.md) | [Transcript](transcripts/20231009/transcript.vtt) |
| 2023-10-11 | Wed | [Episode #31](https://youtu.be/f270ObaKNZw) | wednesday strength for you ✨ | [Summary](summaries/20231011_31.md) | [Transcript](transcripts/20231011/transcript.vtt) |
| 2023-10-13 | Fri | [friday the 13th](https://youtu.be/QW_VwFyUBeU) | i̵͔̠̖͌̈̉̇́̎ẗ̵̢̡̳̦̫̦̫́̌̒͛̀'̷̣̀͐̀́̆s̷̰̦̅͐ ̴̨̻͇͓̼̹̙͋͑f̷̡̩̭͍͇͂̂̓̎̋ü̸̡̙͈̰͚̱̒ẘ̸̧̖̘͈͕͇́̏͐á̶̡̧͔̯̜̬͛́m̶̠̥̮̬̤̮̜̈́̄͂̀̏̈́o̶͚̞͚̐͌͜͝ĉ̵̥̼̀̉̃͝o̷̩͍̠̿̀̉̐͋ ̷̦̂͌ͅm̶͈̣̲̻̖͆̈͘ô̶̢̹̅͊̇̄͝r̸̮͊͌͑n̵̢͉̣̭͚͖̙̿̈́̀i̵̪͙̿̀̄̋͝ͅņ̶͈͎̰̻̘̏g̶͈͔̟͐̓͑̌̄͛͠.̵̡͔̘̣͈̌.̸̡̱̰̔̈́.̶̫͓̃ | [Summary](summaries/20231013_friday_the_13th.md) | [Transcript](transcripts/20231013/transcript.vtt) |
| 2023-10-13 | Fri | [friday the 13th](https://youtu.be/QW_VwFyUBeU) | i̵͔̠̖͌̈̉̇́̎ẗ̵̢̡̳̦̫̦̫́̌̒͛̀'̷̣̀͐̀́̆s̷̰̦̅͐ ̴̨̻͇͓̼̹̙͋͑f̷̡̩̭͍͇͂̂̓̎̋ü̸̡̙͈̰͚̱̒ẘ̸̧̖̘͈͕͇́̏͐á̶̡̧͔̯̜̬͛́m̶̠̥̮̬̤̮̜̈́̄͂̀̏̈́o̶͚̞͚̐͌͜͝ĉ̵̥̼̀̉̃͝o̷̩͍̠̿̀̉̐͋ ̷̦̂͌ͅm̶͈̣̲̻̖͆̈͘ô̶̢̹̅͊̇̄͝r̸̮͊͌͑n̵̢͉̣̭͚͖̙̿̈́̀i̵̪͙̿̀̄̋͝ͅņ̶͈͎̰̻̘̏g̶͈͔̟͐̓͑̌̄͛͠.̵̡͔̘̣͈̌.̸̡̱̰̔̈́.̶̫͓̃ | [Summary](summaries/20231013_friday_the_13th.md) | [Transcript](transcripts/20231013/transcript.vtt) |
| 2023-10-16 | Mon | [Episode #32](https://youtu.be/qTcTR5q0gTk) | power for the new week ✨ | [Summary](summaries/20231016_32.md) | [Transcript](transcripts/20231016/transcript.vtt) |
| 2023-10-18 | Wed | [Episode #33](https://youtu.be/1C4TFSqt_nk) | what day of the week is it again ✨ | [Summary](summaries/20231018_33.md) | [Transcript](transcripts/20231018/transcript.vtt) |
| 2023-10-20 | Fri | [Episode #34](https://youtu.be/WttmEXH3VWs) | fluffy and fuzzy friday ✨ | [Summary](summaries/20231020_34.md) | [Transcript](transcripts/20231020/transcript.vtt) |
Expand Down
18 changes: 11 additions & 7 deletions morning/update_summary_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
EMOJI_FILE = "config/emojis.csv"
NO_EMOJI_EPISODES = ["friday the 13th"]
HEADER_REGEX = re.compile(r"(#+) (.*)\n")
LAST_UPDATED_REGEX = re.compile(r"^Last updated: .*", re.IGNORECASE)
LAST_UPDATED_REGEX = re.compile(r"^Last updated: [^\r\n]*", re.IGNORECASE)
TIMESTAMP_REGEX = re.compile(r"(.*) \((\d+):(\d+)\)")
CURRENT_TIME_STRING = datetime.now(datetime_timezone.utc).strftime("%Y-%m-%d %H:%M")
LAST_UPDATED_STRING = f"Last updated: {CURRENT_TIME_STRING} UTC"
Expand Down Expand Up @@ -162,14 +162,18 @@ def process_summary(
def refresh_file(filename, new_content):
"""Refresh a file with new content if it has changed."""
current_content = []
with open(filename, "r", encoding="utf-8") as f:
line_terminator = "\n"
with open(filename, "r", encoding="utf-8", newline="") as f:
current_content = f.readlines()
if "\r\n" in current_content[0]:
line_terminator = "\r\n"
current_content = [
LAST_UPDATED_REGEX.sub(LAST_UPDATED_STRING, line) for line in current_content
]
if "\n".join(filename) != "\n".join(new_content):
with open("questions.txt", "w", encoding="utf-8") as f:
f.writelines(f"{line}\n" for line in new_content)
new_content = [f"{line}{line_terminator}" for line in new_content]
if current_content != new_content:
with open(filename, "w", encoding="utf-8", newline="") as f:
f.writelines(f"{line}" for line in new_content)
return True
return False

Expand All @@ -178,7 +182,7 @@ def refresh_summary_index(summary_index, summary_table):
"""Refresh the summary index with the latest episode summaries."""
was_updated = refresh_file("index.md", summary_index)
if was_updated:
with open("index.csv", "w", encoding="utf-8") as csvfile:
with open("index.csv", "w", encoding="utf-8", newline="") as csvfile:
fieldnames = [
"Date",
"Episode",
Expand Down Expand Up @@ -221,7 +225,7 @@ def main():
LAST_UPDATED_STRING,
]

with open(EMOJI_FILE, "r", encoding="utf-8") as csvfile:
with open(EMOJI_FILE, "r", encoding="utf-8", newline="") as csvfile:
emoji_list = list(csv.DictReader(csvfile))

for transcript_subdir in os.listdir(args.transcripts_dir):
Expand Down

0 comments on commit 2ae5183

Please sign in to comment.