Skip to content

Commit

Permalink
Add database integration to store generated audio URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanushreddy291 committed Dec 29, 2024
1 parent 4840751 commit 82aff65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
from datetime import datetime, timedelta

from generate_audio import generate_audio_from_text
from llm import generate_reddit_news_summary
from reddit import get_reddit_scraping_tasks
from upload import upload_file
from upload import add_to_db, upload_file

subreddits = ["singularity", "LocalLLaMA", "homeautomation"]

Expand All @@ -22,9 +23,7 @@
text = """========================================
Title: {title}
Description: {description}
""".format(
title=title, description=description
)
""".format(title=title, description=description)
reddit_text += text
print(text)
print(
Expand All @@ -50,4 +49,6 @@

upload_file(audio_path, "hackathon", audio_path)

add_to_db(f"{os.environ.get('AWS_ENDPOINT_URL_S3')}/hackathon/{audio_path}")

print(f"Reddit news summary for {subreddit} generated and uploaded.")
16 changes: 16 additions & 0 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os

import boto3
import psycopg2
from botocore.exceptions import ClientError


Expand Down Expand Up @@ -35,6 +36,17 @@ def upload_file(file_name, bucket, object_name=None, content_type="audio/mpeg"):
return True


def add_to_db(url):
print(f"Adding {url} to the database")
conn = psycopg2.connect(os.environ.get("DATABASE_URL"))
cur = conn.cursor()
cur.execute("INSERT INTO summaries (url) VALUES (%s)", (url,))
conn.commit()
cur.close()
conn.close()
print(f"{url} added to the database.")


if __name__ == "__main__":
file_name = "reddit_news_summary.mp3"
bucket_name = "hackathon"
Expand All @@ -46,3 +58,7 @@ def upload_file(file_name, bucket, object_name=None, content_type="audio/mpeg"):
print(f"File URL: {file_url}")
else:
print("File upload failed.")

url = "https://example.com"
add_to_db(url)
print("URL added to the database.")

0 comments on commit 82aff65

Please sign in to comment.