Spaces:
Sleeping
Sleeping
File size: 829 Bytes
2a89678 c74c973 2a89678 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from pymongo import MongoClient
import certifi
# MongoDB connection string
MONGO_URI = "mongodb+srv://soniyavitkar2712:soniya_27@cluster0.slai2ew.mongodb.net/moodify_db?retryWrites=true&w=majority&appName=Cluster0"
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)
|