Coursework 3

Part B: Make an HTML Playlist

For this part of the assignment you will, as in the previous part, be reading a playlist from a CSV file; but this time you will create an HTML file containing the playlist information, which can be viewed in a web browser, and could potentially be put on the internet (by making the HTML page available via a web server).

You are provided with the following files to help you with this task:

You need to modify and extend 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:

Some example solutions:

Representing and selecting colours in HTML

An HTML color code is a string consisting of a # symbol, followed by six hexadecimal digits, with a hexadecimal digit being one of: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. The first two digits represent the amount of red, the next two the amount of green and the last two the amount of blue light that makes up the color. So, for example, #000000 represents black, #FFFFFF is white, #FF0000 is pure bright red, #C00000 is a muted red, #FF8080 is a pastel red and #FF00FF is magenta. You can experiment with different color codes, or you can easily find the code of a colour you like by using this web-based color chooser tool.

Creating URLs that will Query a Web-Based Search Engine

The following code will return a string of HTML that when included in an HTML web page will create a link that when clicked will execute an YouTube query and take you to a YouTube page that displays the results of the query:
     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:

YouTube search: Python video

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"