You are provided with the following files to help you with this task:
make_html_playlist.py
[View]
[Download]
make_html_table_file.py
[View]
[Download]
make_html_playlist.py
so that the function make_html_playlist(playlist)
creates a HTML file displaying the playlist information in the
file refered to by the playlist argument.
As in Part A, your function should work whether or not the given argument
includes or leaves off the .csv extension. Specifically,
you should check whether the argument
ends in .csv; and, if it does not, you should first add
.csv to get the full name of the file that should be
opened. You also need to output to a file with the extension .html.
If filename argument does not end in .csv then simply add
.html. But if filename does end in .csv then you
should remove that and replace it by .html. So, to be completely
clear, the function should work as follows depending on whether
the arguemnt ents in .csv or not:
| Which files to read from and create | ||
|---|---|---|
| playlist argument | file to read from | file to create |
| "some-playlist" | some-playlist.csv | some-playlist.html |
| "some-playlist.csv" | some-playlist.csv | some-playlist.html |
Your aim is to generate an HTML file that is as attractive and informative as you are able to make it and demonstrates the use of a variety of HTML formatting features
Some features you should consider adding to your HTML playlist webpage:
I'm also using a background image file and another image file for the red play button. Although not provided in the playlist file itself, such images could easily be stored on a web side and links to them added when the playlist web page is generated. If you like you can also do this, in which case you will need to include the required image files along with your submission so that we can see them when we view the web-page generated by your make_html_playlist function.
However, apart from the selected track, the video link and the images, all the other features of this web-page were generated by Python just from the CSV file. In particular the YouTube and Wikipedia search links can be generated just from the track and artist data strings (see below).
def youtube_query_link( query_string, text_string ):
wordlist = query_string.split()
URL = ( "https://www.youtube.com/results?search_query=" +
"+".join(wordlist) ) # Add query terms separated by '+'
# Make string containing the HTML link element
return( '<a href="' + URL + '">' + text_string + '</a>' )
The first argument specifies the query that will be sent to YouTube, which can
be one word or several words separated by spaces. The second argument is the
text of the link that will appear in the browser.
This can be used as follows. Suppose I have this function in my program and execute the function call:
youtube_query_link( "Python video", "YouTube search: Python video" )
This will generate the following string of HTML:
'<a href="https://www.youtube.com/results?search_query=Python+video">YouTube search: Python video</a>'If you then embed this into an HTML file (e.g. by using a Python
write command) and view it in a browser, you will get the following
link:
Try clicking it and see what happens.
A similar idea can be used to create a link that will search using another
searchable resource, such as Google or Wikipedia. But the exact format
used to specify the search will vary according to the particular resource.
For example, to create a search link for Wikipedia, you need to create
a link with the URL (i.e. the value of href) being of the
following form (if there are several search
words they should be joined by an underscore symbol):
"https://en.wikipedia.org/?search=word1_word2"