Skip to content

Commit

Permalink
Loging Seems to be working, other sections still an issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeisacanvas24 committed Oct 13, 2024
1 parent 7c063ee commit 922783f
Show file tree
Hide file tree
Showing 111 changed files with 2,124 additions and 2,944 deletions.
107 changes: 94 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,100 @@
Pagination
IG / YT datafeed
contrnt for the entire website
To integrate an Instagram feed into your Zola-based site, you’ll need to follow these steps:
1. Use an Instagram API or Third-Party Service
There are two main approaches to adding an Instagram feed to your site:
1. Instagram’s Graph API (official but requires creating an app, managing access tokens, etc.)
2. Third-Party Services (simpler but may come with limitations or branding)
Option 1: Using Instagram’s Graph API
To use the Instagram API:
1. Create a Facebook App:
• Go to the Facebook for Developers website and create an app.
• Get access to Instagram Basic Display or Instagram Graph API.
2. Get Access Tokens:
• Follow the Instagram Graph API Guide to get an access token.
3. Fetch Instagram Feed:
Use curl or a HTTP library (e.g., using JavaScript’s fetch API) to request recent posts via Instagram’s API. For example:
curl -X GET "https://graph.instagram.com/me/media?fields=id,caption,media_url&access_token=YOUR_ACCESS_TOKEN"
Display the Feed in Zola:
Write a custom shortcode or macro in Zola that fetches the feed and displays it in your templates.
Example JavaScript Code for Fetching Instagram Feed:
<script>
fetch('https://graph.instagram.com/me/media?fields=id,media_url,caption&access_token=YOUR_ACCESS_TOKEN')
.then(response => response.json())
.then(data => {
let output = '';
data.data.forEach(post => {
output += `<div class="instagram-post">
<img src="${post.media_url}" alt="Instagram Image">
<p>${post.caption}</p>
</div>`;
});
document.getElementById('instagram-feed').innerHTML = output;
})
.catch(err => console.log(err));
</script>
In your Zola template (index.html or any other page), you would have something like this to display the feed:
<div id="instagram-feed"></div>
Option 2: Using a Third-Party Service
If you prefer a simpler approach, you can use third-party services that allow you to embed Instagram feeds:
1. Embed Instagram Feed Using Tools like SnapWidget or LightWidget
• Services like SnapWidget or LightWidget allow you to create Instagram widgets with minimal effort.
• Sign up for one of these services and customize the widget (size, layout, etc.).
• After customization, you’ll get an embed code that you can place in your Zola template.
<div class="instagram-feed">
<iframe src="https://snapwidget.com/embed/xxxx" allowtransparency="true" frameborder="0" scrolling="no" style="border:none; overflow:hidden; width:100%; height:400px"></iframe>
</div>
2. Add Instagram Feed to Your Zola Template
After choosing an approach, add the appropriate code to your Zola layout or page templates.
Example Template Usage:
If you’re using a third-party widget, add the widget code to your Zola template. For example, in your base.html or index.html:
<section class="section">
<div class="container">
<h2 class="title is-4">Our Instagram Feed</h2>
<!-- Add Instagram Feed Embed Code -->
<div class="instagram-feed">
<iframe src="https://snapwidget.com/embed/xxxx" allowtransparency="true" frameborder="0" scrolling="no" style="border:none; overflow:hidden; width:100%; height:400px"></iframe>
</div>
</div>
</section>

Styling with Bulma:

You can apply Bulma classes to style the feed nicely.
<section class="section">
<div class="container">
<h2 class="title is-4">Follow us on Instagram</h2>
<div class="columns is-multiline">
<div class="column is-one-quarter">
<!-- Instagram post goes here -->
</div>
<!-- Repeat for other posts -->
</div>
</div>
</section>


content for the entire website
dynamic parts to be handle using astro.build
defining .md template
exploring more commoponents from bulma
daisy css
Here are some ideas to get you started:
- 🔭 I’m currently working on ...
- 🌱 I’m currently learning ...
- 👯 I’m looking to collaborate on ...
- 🤔 I’m looking for help with ...
- 💬 Ask me about ...
- 📫 How to reach me: ...
- 😄 Pronouns: ...
- ⚡ Fun fact: ...
-->
daisy css
224 changes: 224 additions & 0 deletions bash/ai-git-commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
#!/usr/bin/env python3

import json
import logging
import os
import subprocess
from typing import List, Optional

import openai

# File paths
STARSHIP_LOGS = os.path.expanduser("~/.starship/logs")
CACHE_FILE = os.path.join(STARSHIP_LOGS, "ai-commit-cache")
FEEDBACK_LOG = os.path.join(STARSHIP_LOGS, "ai-commit-feedback.log")
LAST_RESPONSE_LOG = os.path.join(STARSHIP_LOGS, "last-openai-response.log")
REQUEST_LOG = os.path.join(STARSHIP_LOGS, "openai-request-payload.log")
STARTSHIP_STATUS_LOG = os.path.join(STARSHIP_LOGS, "ai-commit-status-starship.log")
API_KEY_PATH = os.path.expanduser("~/.ssh/openai-api-key")

'''# Available OpenAI models
MODEL_DESCRIPTIONS = {
"gpt-3.5-turbo": "Fastest and most cost-effective model, good for most everyday tasks",
"gpt-4": "More capable model, better for complex tasks and reasoning",
"gpt-4-turbo": "Most advanced model, best for specialized and demanding applications",
}
DEFAULT_MODEL = "gpt-3.5-turbo"
MODEL = DEFAULT_MODEL
'''

# Create log directories if they don't exist
os.makedirs(STARSHIP_LOGS, exist_ok=True)

logging.basicConfig(
filename=STARTSHIP_STATUS_LOG,
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)

def safe_input(prompt, max_attempts=3):
for attempt in range(max_attempts):
try:
result = input(prompt)
return result.strip()
except EOFError:
logging.error("End of file reached unexpectedly")
continue
except KeyboardInterrupt:
logging.error("User interrupted")
return None
except Exception as e:
logging.exception(f"Unexpected error occurred: {str(e)}")
return None
return None

def load_api_key():
api_key_path = API_KEY_PATH
if not os.path.exists(api_key_path):
logging.error(f"API key file not found at {api_key_path}")
raise FileNotFoundError(f"API key file not found at {api_key_path}")

with open(api_key_path, 'r') as f:
api_key = f.read().strip()

if not api_key:
logging.error("Empty API key file")
raise ValueError("Empty API key file")

return api_key

def get_staged_files() -> List[str]:
try:
result = subprocess.run(
["git", "diff", "--cached", "--name-only"],
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip().split("\n")
except subprocess.CalledProcessError as e:
logging.error(f"Error getting staged files: {e}")
raise

def get_staged_changes_for_file(file_path: str) -> str:
try:
result = subprocess.run(
["git", "diff", "--cached", file_path],
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
except subprocess.CalledProcessError as e:
logging.error(f"Error getting changes for file {file_path}: {e}")
return ""

def get_commit_message_suggestions(prompt: str) -> List[str]:
api_key = load_api_key()
openai.api_key = api_key

try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
top_p=1,
n=5
)
return [choice['message']['content'] for choice in response['choices']]
except Exception as e:
logging.error(f"Error fetching suggestions: {str(e)}")
return []

def prompt_user_for_input(suggestions: List[str]) -> Optional[str]:
print("\nCommit message suggestions:")
for i, suggestion in enumerate(suggestions, 1):
print(f"{i}. {suggestion}")

while True:
choice = safe_input("\nEnter the number of your preferred suggestion, or 'c' for custom: ")
if choice.lower() == "c":
return None
try:
num = int(choice)
if 1 <= num <= len(suggestions):
return suggestions[num - 1]
else:
print("Invalid selection. Please choose a valid option.")
except ValueError:
print("Invalid input. Please enter a number or 'c'.")

def commit_file(file_path: str, message: str) -> None:
try:
subprocess.run(["git", "commit", "-m", f"{file_path}: {message}"], check=True)
logging.info(f"Successfully committed file: {file_path}")
except subprocess.CalledProcessError as e:
logging.error(f"Failed to commit file {file_path}: {e}")

def get_diff():
return subprocess.check_output(["git", "diff", "--staged"]).decode("utf-8")

def extract_comments_from_diff(diff_output):
lines = diff_output.split("\n")
comments = [
line
for line in lines
if line.strip().startswith(("#", "//", "/*", "*/", "<!--", "--"))
]
if comments:
logging.info(f"Comments found: {' '.join(comments)}")
else:
logging.info("No comments found in the diff.")
return " ".join(comments)

def log_request(prompt, model):
with open(REQUEST_LOG, "w") as log_file:
log_file.write(f"Model: {model}\nPrompt: {prompt}\n")

def log_response(response):
with open(LAST_RESPONSE_LOG, "w") as log_file:
log_file.write(json.dumps(response, indent=4))

def ai_git_commit():
try:
staged_files = get_staged_files()
if not staged_files:
logging.warning("No staged files found. Exiting.")
return

logging.info(f"Found {len(staged_files)} staged files")

print("\nStaged files:")
for i, file in enumerate(staged_files, start=1):
print(f"{i}. {file}")

selected_files = []
custom_messages = {}

for i, file in enumerate(staged_files, start=1):
print(f"\nFile {i}: {file}")
response = input("Do you want to commit this file? (y/n): ")
if response.lower() == "y":
selected_files.append(i)

prompt = f"""Here's a summary of the changes for {file}:
{get_staged_changes_for_file(file)}
Please provide a brief description of the changes."""

suggestions = get_commit_message_suggestions(prompt)
selected_message = prompt_user_for_input(suggestions)

if selected_message is None:
selected_message = safe_input(f"Please provide a custom commit message for {file}: ")

custom_messages[file] = selected_message

if not selected_files:
logging.warning("No files selected for commit. Exiting.")
return

diff_output = get_diff()
comments = extract_comments_from_diff(diff_output)
logging.info(f"Comments found in the diff: {comments}")

for file_index in selected_files:
file = staged_files[file_index - 1]
commit_file(file, custom_messages[file])
logging.info(f"Successfully committed file: {file}")

logging.info("All selected files committed successfully.")

except EOFError:
logging.error("End of file reached unexpectedly")
except KeyboardInterrupt:
logging.error("User interrupted")
except Exception as e:
logging.exception(f"An unexpected error occurred: {str(e)}")
print(f"An unexpected error occurred: {str(e)}")

if __name__ == "__main__":
ai_git_commit()
Loading

0 comments on commit 922783f

Please sign in to comment.