Skip to content

Instantly share code, notes, and snippets.

@bethropolis
Last active October 27, 2023 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bethropolis/1ed56cb40c773165f83ad9561b460a0e to your computer and use it in GitHub Desktop.
Save bethropolis/1ed56cb40c773165f83ad9561b460a0e to your computer and use it in GitHub Desktop.
a python program for getting song recommendation from a playlist.
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