Last active
October 27, 2023 19:32
-
-
Save bethropolis/1ed56cb40c773165f83ad9561b460a0e to your computer and use it in GitHub Desktop.
a python program for getting song recommendation from a playlist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import random | |
playlists=["trap","hiphop"] | |
query = input("Enter song name or artist name: ").lower() | |
def load_songs(file): | |
file_path = file + ".json" | |
with open(file_path) as f: | |
songs = json.load(f) | |
for song in songs: | |
if(song["artist"].lower() == query or song["song"].lower() == query): | |
print("found song by", song["artist"],"song is", song["song"],"\n") | |
print("here are some other songs similar to", song["song"],"") | |
for i in range(3): | |
no_key = random.randint(0, len(songs)); | |
print(i,".",songs[no_key]["song"],"by",songs[no_key]['artist']) | |
return True; | |
return False; | |
for file in playlists: | |
if(load_songs(file)): | |
break | |
else: | |
print("Song not found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment