In this assignment you will practice data transfer techniques such as
You have a list of songs in a comma-separated values file and you want to publish it as a playlist to a site that supports the JSPF JSON format for sharing playlists.
Write a Python program in a file named csv2jspf.py
that reads a CSV file containing song information and writes the song information to a playlist file in JSPF JSON format.
;
, not ,
..csv
extension.Look at the JSPF specification (which is given as a couple of easily read examples). Use the base name of the input file (the part before .csv
) as the title
of the playlist, yourself as the creator
, the tracks in track
(note the badly-named singular noun for list of tracks) come from the records in the CSV input file, and and write the playlist data to a JSPF-formatted JSON file with the same base name as the input file, but with a .json
extension. Keep the following in mind:
If you ran your program on the weird-al.csv input file we provided, your JSPF file would look something like this (this has been reformatted for readability):
{
"playlist": {
"title": "weird-al",
"creator": "chris",
"duration": 1986,
"track": [
{
"title": "A Complicated Song (Parody of \"Complicated\" by Avril Lavigne)",
"duration": 219,
"creator": "Weird Al Yankovic",
"album": "Poodle Hat",
"location": "https://itunes.apple.com/us/album/a-complicated-song-parody-of-complicated-by-avril-lavigne/206901097?i=206902871"
},
{
"title": "Ebay (Parody of \"I Want It That Way\" by the Backstreet Boys)",
"duration": 216,
"creator": "Weird Al Yankovic",
"album": "Poodle Hat",
"location": "https://itunes.apple.com/us/album/ebay-parody-of-i-want-it-that-way-by-the-backstreet-boys/206901097?i=206903768"
},
{
"title": "Fat",
"duration": 217,
"creator": "Weird Al Yankovic",
"album": "Even Worse",
"location": "https://itunes.apple.com/us/album/fat/250500424?i=250500433"
},
{
"title": "Eat It",
"duration": 200,
"creator": "Weird Al Yankovic",
"album": "In 3-D",
"location": "https://itunes.apple.com/us/album/eat-it/250495308?i=250495319"
},
{
"title": "Smells Like Nirvana",
"duration": 222,
"creator": "Weird Al Yankovic",
"album": "Off the Deep End",
"location": "https://itunes.apple.com/us/album/smells-like-nirvana/250495074?i=250495085"
},
{
"title": "Amish Paradise (Parody of \"Gangsta's Paradise\" by Coolio)",
"duration": 200,
"creator": "Weird Al Yankovic",
"album": "Bad Hair Day",
"location": "https://itunes.apple.com/us/album/amish-paradise-parody-of-gangstas-paradise-by-coolio/206900040?i=206900081"
},
{
"title": "White & Nerdy (Parody of \"Ridin'\" By Chamillionaire featuring Krayzie Bone)",
"duration": 170,
"creator": "Weird Al Yankovic",
"album": "Straight Outta Lynwood",
"location": "https://itunes.apple.com/us/album/white-nerdy-parody-of-ridin/309731664?i=309732001"
},
{
"title": "Party In the CIA (Parody of \"Party In the U.S.A.\" By Miley Cyrus)",
"duration": 176,
"creator": "Weird Al Yankovic",
"album": "Alpocalypse",
"location": "https://itunes.apple.com/us/album/party-in-the-cia-parody-of-party-in-the-u-s-a-by-miley-cyrus/438383158?i=438383166"
},
{
"title": "Canadian Idiot (Parody of \"American Idiot\" By Green Day)",
"duration": 143,
"creator": "Weird Al Yankovic",
"album": "Straight Outta Lynwood",
"location": "https://itunes.apple.com/us/album/canadian-idiot-parody-of-american-idiot-by-green-day/309731664?i=309732012"
},
{
"title": "Word Crimes",
"duration": 223,
"creator": "Weird Al Yankovic",
"album": "Mandatory Fun",
"location": "https://itunes.apple.com/us/album/word-crimes/891836396?i=891836406"
}
]
}
}
Note that the example above is pretty-printed to look like the JSPF specification and key-value pairs may appear in any order.
$ python csv2jspf.py weird-al.csv
produces weird-al.json
.
track
key in the JDPF format.Bonus (10 points): add a duration
key to the JSPF playlist object whose value is the total running time of the playlist in seconds.
title
attribute with correct value.creator
attribute with correct value.track
attribute with list containing all songs from input file.title
attribute with correct value.duration
attribute with correct value.creator
attribute with correct value.album
attribute with correct value.location
attribute with correct value.duration
attribute with correct value.Submit your csv2jspf.py
file on Canvas as an attachment. When you’re ready, double-check that you have submitted and not just saved a draft.
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.