Some checks failed
Create Blog Article if new notes exist / prepare_blog_drafts_and_push (push) Failing after 27m5s
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
import ai_generators.ollama_md_generator as omg
|
|
import trilium.notes as tn
|
|
import repo_management.repo_manager as git_repo
|
|
from notifications.n8n import N8NWebhookJwt
|
|
import string,os
|
|
from datetime import datetime
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
print(os.environ["CONTENT_CREATOR_MODELS"])
|
|
|
|
|
|
tril = tn.TrilumNotes()
|
|
|
|
tril.get_new_notes()
|
|
tril_notes = tril.get_notes_content()
|
|
|
|
|
|
def convert_to_lowercase_with_underscores(s):
|
|
allowed = set(string.ascii_letters + string.digits + ' ')
|
|
filtered_string = ''.join(c for c in s if c in allowed)
|
|
return filtered_string.lower().replace(" ", "_")
|
|
|
|
|
|
for note in tril_notes:
|
|
print(tril_notes[note]['title'])
|
|
# print(tril_notes[note]['content'])
|
|
print("Generating Document")
|
|
|
|
os_friendly_title = convert_to_lowercase_with_underscores(tril_notes[note]['title'])
|
|
ai_gen = omg.OllamaGenerator(os_friendly_title,
|
|
tril_notes[note]['content'],
|
|
tril_notes[note]['title'])
|
|
blog_path = f"generated_files/{os_friendly_title}.md"
|
|
ai_gen.save_to_file(blog_path)
|
|
|
|
|
|
# Generate commit messages and push to repo
|
|
print("Generating Commit Message")
|
|
git_sytem_prompt = "You are a blog creator commiting a piece of content to a central git repo"
|
|
git_human_prompt = f"Generate a 5 word git commit message describing {ai_gen.response}. ONLY OUTPUT THE RESPONSE"
|
|
commit_message = ai_gen.generate_system_message(git_sytem_prompt, git_human_prompt)
|
|
git_user = os.environ["GIT_USER"]
|
|
git_pass = os.environ["GIT_PASS"]
|
|
repo_manager = git_repo.GitRepository("blog/", git_user, git_pass)
|
|
print("Pushing to Repo")
|
|
repo_manager.create_copy_commit_push(blog_path, os_friendly_title, commit_message)
|
|
|
|
# Generate notification for Matrix
|
|
print("Generating Notification Message")
|
|
git_branch_url = f'https://git.aridgwayweb.com/armistace/blog/src/branch/{os_friendly_title}/src/content/{os_friendly_title}.md'
|
|
n8n_system_prompt = f"You are a blog creator notifiying the final editor of the final creation of blog available at {git_branch_url}"
|
|
n8n_prompt_human = f"""
|
|
Generate an informal 150 word
|
|
summary describing {ai_gen.response}.
|
|
Don't address it or use names. ONLY OUTPUT THE RESPONSE
|
|
"""
|
|
notification_message = ai_gen.generate_system_message(n8n_system_prompt, n8n_prompt_human)
|
|
secret_key = os.environ['N8N_SECRET']
|
|
webhook_url = os.environ['N8N_WEBHOOK_URL']
|
|
notification_string = f"""
|
|
<h2>{tril_notes[note]['title']}</h2>
|
|
<h3>Summary</h3>
|
|
<p>{notification_message}</p>
|
|
<h3>Branch</h3>
|
|
<p>{os_friendly_title}</p>
|
|
<p><a href="{git_branch_url}">Link to Branch</a></p>
|
|
"""
|
|
|
|
payload = {
|
|
"message": f"{notification_string}",
|
|
"timestamp": datetime.now().isoformat()
|
|
}
|
|
|
|
webhook_client = N8NWebhookJwt(secret_key, webhook_url)
|
|
|
|
print("Notifying")
|
|
n8n_result = webhook_client.send_webhook(payload)
|
|
|
|
print(f"N8N response: {n8n_result['status']}")
|