-
Notifications
You must be signed in to change notification settings - Fork 1
/
weeklylinks.py
93 lines (78 loc) · 2.37 KB
/
weeklylinks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
from datetime import datetime
import random
def get_user_input():
url = input("Enter the URL: ")
comment = input("Enter an optional comment (press Enter to skip): ")
link_text = input("Enter the link text: ")
return url, comment, link_text
def generate_random_intro():
intros = [
"Here are this week's interesting links:",
"Check out these fascinating links from the past week:",
"Dive into this week's curated collection of links:",
"Explore the following intriguing links I've gathered:",
"This week's roundup of captivating links awaits you:"
]
return random.choice(intros)
def generate_random_goodbye():
goodbyes = [
"See you next time!",
"Until next week!",
"Enjoy!",
"That's all for now.",
"That's all folks."
]
return random.choice(goodbyes)
def format_content(links):
now = datetime.now()
date_text = now.strftime("%B %d, %Y")
date_format = now.strftime("%Y-%m-%d")
content = f"""---
title: "Weekly Links for {date_text}"
date: {date_format}
draft: false
ShowToc: false
cover:
image: "/link-cover.jpg"
relative: true
tags: ["weekly links"]
params:
description: "Weekly Links for {date_text}."
images:
- "/link-cover.jpg"
title: "Weekly Links for {date_text}."
images:
- "/link-cover.jpg"
---
{generate_random_intro()}
"""
for link in links:
url, comment, link_text = link
if comment:
content += f"* {comment}: [{link_text}]({url})\n"
else:
content += f"* [{link_text}]({url})\n"
content += f"\n{generate_random_goodbye()}"
return content
def save_to_file(content):
now = datetime.now()
filename = now.strftime("%m%d%Y.md")
folder_path = os.path.join("content", "posts", "weekly-links")
os.makedirs(folder_path, exist_ok=True)
file_path = os.path.join(folder_path, filename)
with open(file_path, "w") as f:
f.write(content)
print(f"File saved: {file_path}")
def main():
links = []
while True:
url, comment, link_text = get_user_input()
links.append((url, comment, link_text))
another = input("Do you want to add another link? (y/n): ").lower()
if another != 'y':
break
content = format_content(links)
save_to_file(content)
if __name__ == "__main__":
main()