New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Database with Python_Coursera_Musical Track Database #16
Comments
Greetings! |
Yeah you can do that but there is a line to avoid precisely those NoneType objects which lacks the variable genre:
That genre is not in the sample code (tracks.py). However I still haven't managed to the expected result. Mine is
What about you? |
It's fine, I think his playlist updated, I click submit and it was all cool. |
i have done the same thing but still getting error while submitting |
try using this SQL command:
|
Try the below one, it will work perfectly import xml.etree.ElementTree as ET conn = sqlite3.connect('trackdb.sqlite') CREATE TABLE Artist ( CREATE TABLE Genre ( CREATE TABLE Album ( CREATE TABLE Track ( fname = input('Enter file name: ') def lookup(d, key): stuff = ET.parse(fname)
|
Iy's not working the genre table has no values and the column genre_id is not even created |
I have a question regarding the Lookup() function. why doesn't the first if clause come after the second? |
take for example < key >Name< / key >< string >Hello World</ string >, the first time the loop is searching in < key >Name</ key >, the second if statement in the for loop here when looking through the xml file found the tag ( 'key' with child.tag) and the text inside it(Name child.text), now if you were to take these values you wouldn't solve the problem at hand because what you actually need is Hello World not Name, so now by setting the value of found to true the loop will start again with a true value while searching in < string >Hello World< /string > and thus executing the first if statement which is child.text which in this case is Hello World, so you got what you needed. |
trying to add if genre is None: before you cur.execute in sqlite might help you if you got the error of 'TypeError: 'NoneType' object is not subscriptable' |
Hello. Need help. I tried to run the code tracks.py on pythonanywhere and I don't understand the problem. New database file would be created but empty. I think it's because of this errormessages: This is the original code which I got from py4e.orgimport xml.etree.ElementTree as ET conn = sqlite3.connect('trackdb.sqlite') Make some fresh tables using executescript()cur.executescript(''' CREATE TABLE Artist ( CREATE TABLE Album ( CREATE TABLE Track ( fname = input('Enter file name: ') Track ID369NameAnother One Bites The DustArtistQueendef lookup(d, key): stuff = ET.parse(fname)
|
Hi, the below code works perfectly and all the issues are fixed. (Track table has genre_id data and the Genre table has data in it) `import xml.etree.ElementTree as ET conn = sqlite3.connect('trackdb.sqlite') cur.executescript(''' CREATE TABLE Artist ( CREATE TABLE Genre ( CREATE TABLE Album ( CREATE TABLE Track ( fname = input('Enter file name: ') def lookup(d, key): stuff = ET.parse(fname)
` |
Is not working, getting the following error: line 41 Has anybody been able to crack this one? I been stuck for days, need some help |
Can someone help me with this part , i am not able to understand it. def lookup(d, key): |
import xml.etree.ElementTree as ET conn = sqlite3.connect('trackdb.sqlite') cur.executescript(''' CREATE TABLE Artist ( CREATE TABLE Genre ( CREATE TABLE Album ( CREATE TABLE Track ( fname = input('Enter file name: ') def lookup(d, key): stuff = ET.parse(fname)
|
`import sqlite3 #Function that we'll use to find the content of a specific field.
#PART 1: PREPARING THE DATABASE #Getting sure it is empty
#Creating it #PART 2: INSERTING THE DATA #Obtaining every tag with track data #Getting the values of the fields we'll insert
conn.commit() |
which file do i have to open i am also having some issues with sql db can someone send an ss |
This code worked perfectly. The answers were different than what was posted on the assignment page, but it submitted with no issues.
|
`import xml.etree.ElementTree as ET fname = input('Enter file name: ') # Changed 'raw_input' to 'input' for Python 3 compatibility Track ID369NameAnother One Bites The DustArtistQueenGenreIndustrialdef lookup(d, key): Assume you have already created the SQLite connection and cursor objects (conn and cur)You need to have the 'conn' and 'cur' objects defined and connected to the database.Create an element tree and find branchestree = ET.parse(fname) for entry in all_dicts:
I am getting the error as after submitting Please Help |
This application will read an iTunes export file in XML and produce a properly normalized database with this structure:
CREATE TABLE Artist (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT UNIQUE
);
CREATE TABLE Genre (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT UNIQUE
);
CREATE TABLE Album (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
artist_id INTEGER,
title TEXT UNIQUE
);
CREATE TABLE Track (
id INTEGER NOT NULL PRIMARY KEY
AUTOINCREMENT UNIQUE,
title TEXT UNIQUE,
album_id INTEGER,
genre_id INTEGER,
len INTEGER, rating INTEGER, count INTEGER
);
If you run the program multiple times in testing or with different files, make sure to empty out the data before each run.
You can use this code as a starting point for your application: http://www.pythonlearn.com/code/tracks.zip. The ZIP file contains the Library.xml file to be used for this assignment. You can export your own tracks from iTunes and create a database, but for the database that you turn in for this assignment, only use the Library.xml data that is provided.
To grade this assignment, the program will run a query like this on your uploaded database and look for the data it expects to see:
SELECT Track.title, Artist.name, Album.title, Genre.name
FROM Track JOIN Genre JOIN Album JOIN Artist
ON Track.genre_id = Genre.ID and Track.album_id = Album.id
AND Album.artist_id = Artist.id
ORDER BY Artist.name LIMIT 3
The expected result of this query on your database is:
Track Artist Album Genre
Chase the Ace AC/DC Who Made Who Rock
D.T. AC/DC Who Made Who Rock
For Those About To Rock (We Salute You) AC/DC Who Made Who Rock
My Solution
The text was updated successfully, but these errors were encountered: