```python import os import sys from git import Repo, GitCommandError def clone_repo(repo_url, branch="main"): try: Repo.clone_from(repo_url, ".", branch=branch) except GitCommandError as e: print(f"Error cloning repository: {e}") sys.exit(1) def create_markdown_file(file_name, content): try: with open(f"{file_name}.md", "w") as f: f.write(content) except IOError as e: print(f"Error creating Markdown file: {e}") sys.exit(1) def commit_and_push(file_name, message): repo = Repo(".") try: repo.index.add([f"{file_name}.md"]) repo.index.commit(message) repo.remote().push() except GitCommandError as e: print(f"Error committing and pushing changes: {e}") sys.exit(1) def create_new_branch(branch_name): repo = Repo(".") try: repo.create_head(branch_name).checkout() repo.head.reference.set_tracking_url( f"https://your_git_server/{REPO_OWNER}/{REPO_NAME}.git/{branch_name}" ) repo.remote().push() except GitCommandError as e: print(f"Error creating new branch: {e}") sys.exit(1) if __name__ == "__main__": if len(sys.argv) < 3: print("Usage: python push_markdown.py <repo_url> <markdown_file_name>") sys.exit(1) repo_url = sys.argv[1] file_name = sys.argv[2] # Clone the repository clone_repo(repo_url) # Create a new Markdown file with content create_markdown_file(file_name, "Hello, World!\n") print(f"Created '{file_name}.md' successfully.") # Commit and push changes to the main branch commit_and_push(file_name, f"Add {file_name}.md") print("Changes committed and pushed to main branch.") # Create a new branch named after the Markdown file create_new_branch(file_name) print(f"Successfully created '{file_name}' branch with '{file_name}.md'.") ``` Now, the script includes error handling for cloning the repository, creating the Markdown file, committing and pushing changes, and creating a new branch. It also provides better output formatting by printing success messages after each step. To use this updated script, run it from the command line like this: ```bash python push_markdown.py https://your_git_server/username/repo.git my_new_file ``` This will clone the repository, create a new Markdown file named `my_new_file.md`, commit and push changes to the main branch, create a new branch named `my_new_file`, and print success messages for each step.
BLOG CREATOR
This creator requires you to use a working Trilium Instance and create a .env file with the following
TRILIUM_HOST
TRILIUM_PORT
TRILIUM_PROTOCOL
TRILIUM_PASS
This container is going to be what I use to trigger a blog creation event
To do this we will
- Download a Note from Trillium (I need to work out how to choose this, maybe something with a tag and then this can add a tag when it's used? each note is a seperate post, a tag to indicate if it's ready as well?)
SELECT NOTES WHERE blog_tag = true AND used_tag = false AND ready_tag = true?
- Check if the ollama server is available (it's currently on a box that may not be on)
- If not on stop
git pull git.aridgwayweb.com/blog
-
set up git creds: git.name = ai git.email = ridgwayinfrastructure@gmail.com get git password stored (create service user in gitea for this)
-
git config set upstream Auto true
-
cd /src/content
-
take the information from the trillium note and prepare a 500 word blog post, insert the following at the top
Title: <title>
Date: <date post created>
Modified: <date post created>
Category: <this will come from a tag on the post (category: <category>)
Tags: <ai generated tags>, ai_content, not_human_content
Slug: <have ai write slug?>
Authors: <model name>.ai
Summary: <have ai write a 10 word summary of the post
-
write it to
<title>.md
-
git checkout -b <title>
-
git add .
-
git commit -m "<have ai write a git commit about the post>"
-
git push
-
Send notification via n8n to matrix for me to review?
Description
Languages
Python
96.6%
Dockerfile
3.4%