-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
47 lines (40 loc) · 1.39 KB
/
app.py
File metadata and controls
47 lines (40 loc) · 1.39 KB
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
from jinja2 import Environment, FileSystemLoader
from datetime import datetime, timezone
from pathlib import Path
script_dir = Path(__file__).parent.resolve()
env = Environment(
loader=FileSystemLoader(script_dir / 'templates'),
autoescape=False
)
import utils.bot as bot
import utils.project as project
import utils.history as history
def process(article):
try:
template = env.get_template('generate.md')
prompt = template.render(
title=article['title'],
url=article['url'],
article=project.read(article['path']),
headings=article['headings'],
date=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
dd_date=datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
)
post_content = bot.get_post(prompt)
return history.write({
'article': article,
'content': post_content
})
except Exception as e:
print(f"Error processing article '{article.get('title', 'unknown')}': {e}")
return None
if __name__ == '__main__':
template = env.get_template('prompt.md')
prompt = template.render(
articles=project.get(),
visited=history.get(),
datetime=datetime.now(timezone.utc).strftime("%Y-%m-%d (%W %w) %H:%M:%S")
)
choices = bot.get_choice(prompt)
result = [process(article) for article in choices]
print(result)