dimanche 12 novembre 2017

PYTHON SQLITE3: randomly select fields which when fetched don't exceed 10

I'm a beginner in python. I have a database with song titles, artist, genre and song lengths. I would like my program to automatically generate a text file which contains songs (and their database data) whose song length does not exceed 10 (minutes) and/or contains songs with only a specified genre. My database containing the songs.

I know all about .fetchall and .fetchone and SELECT statements but I'm still struggling a lot to even get a start on this program because I do not know how to apporach it.

conn = sqlite3.connect("songs.db")
c = conn.cursor()

genres = ['Pop', 'Hip-Hop', 'House']
user_length = int(input("What's will be maximum time limit of your playlist?"))

while user_length < 2.6:
    user_length = int(input("That length is too small! Try a higher time limit!"))

user_genre = str(input("What genre do you want your playlist based on?"))

while user_genre not in genres:
    user_genre = str(input("You can only choose Pop, Hip-Hop or House..."))



conn.commit()
c.close()
conn.close()




Aucun commentaire:

Enregistrer un commentaire