moodify_textModel / textModel /checkMongo.py
vancyferns
added textModel files to github repo
2a89678
raw
history blame
734 Bytes
from pymongo import MongoClient
import certifi
import os
# MongoDB connection string
MONGO_URI = os.getenv("MONGO_URI")
if not MONGO_URI:
raise ValueError("MONGO_URI environment variable is not set")
# Connect using certifi's CA bundle
client = MongoClient(MONGO_URI, tlsCAFile=certifi.where())
# Access database and collection
db = client["moodify_db"]
collection = db["songs_by_emotion"]
# Function to fetch songs by emotion
def get_songs_by_emotion(emotion):
results = collection.find({"emotion": emotion})
return list(results)
# Main
if __name__ == "__main__":
emotion = input("Enter an emotion (e.g. happy, sad, angry): ")
songs = get_songs_by_emotion(emotion)
for song in songs:
print(song)