{"id":1120,"date":"2013-03-13T19:53:58","date_gmt":"2013-03-13T18:53:58","guid":{"rendered":"http:\/\/denbeke.be\/blog\/?page_id=1120"},"modified":"2013-03-13T19:53:58","modified_gmt":"2013-03-13T18:53:58","slug":"itunes-library-parser-tablegenerator","status":"publish","type":"page","link":"https:\/\/denbeke.be\/blog\/itunes-library-parser\/itunes-library-parser-tablegenerator\/","title":{"rendered":"iTunes Library Parser &#8211; TableGenerator"},"content":{"rendered":"<pre><code data-language=\"python\">class TableGenerator:\r\n'''Class for generating a HTML file with a list of albums. Input comes from iTune Library XML file'''\r\n\r\ndef __init__(self, input_file, output_file):\r\n    '''Constructor'''\r\n\r\n    #html header\r\n    self.htmlHeader = \"&lt;!DOCTYPE html&gt;&lt;html lang=\\\"en\\\"&gt;&lt;head&gt;&lt;meta charset=\\\"utf-8\\\"&gt;&lt;title&gt;iTunes Albums&lt;\/title&gt;&lt;!--[if lt IE 9]&gt;&lt;script src=\\\"http:\/\/html5shim.googlecode.com\/svn\/trunk\/html5.js\\\"&gt;&lt;\/script&gt;&lt;![endif]--&gt;&lt;\/head&gt;&lt;body&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Album&lt;\/th&gt;&lt;th&gt;Artiest&lt;\/th&gt;&lt;th&gt;Year&lt;\/th&gt;&lt;\/tr&gt;\"\r\n\r\n    #empty content, content is created with generateHTMLContent()\r\n    self.htmlContent = \"\"\r\n\r\n    #html footer\r\n    self.htmlFooter = \"&lt;\/tbody&gt;&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;\"\r\n\r\n    self.albumList = AlbumListGenerator(input_file)\r\n    self.outputFile = output_file\r\n    self.albumList.generateList()\r\n\r\ndef generateHTMLContent(self):\r\n    '''Generates the string containing the albums formatted in HTML'''\r\n\r\n    #Loop through all albuls\r\n    for album in self.albumList.getList():\r\n        line = \"\" #reset line\r\n        line += \"&lt;tr&gt;&lt;td&gt;\"+album.getAlbum()+\"&lt;\/td&gt;&lt;td&gt;\"+album.getArtist()+\"&lt;\/td&gt;&lt;td&gt;\"+album.getYear()+\"&lt;\/td&gt;&lt;\/tr&gt;\" #format line           \r\n        self.htmlContent += line #Add line to content\r\n\r\ndef writeFile(self):\r\n    '''Writes the html code to a file'''\r\n    self.generateHTMLContent()\r\n    file = open(outputFile, 'w')\r\n    file.write(self.htmlHeader+self.htmlContent+self.htmlFooter)\r\n    file.close()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>class TableGenerator: &#8221;&#8217;Class for generating a HTML file with a list of albums. Input comes from iTune Library XML file&#8221;&#8217; def __init__(self, input_file, output_file): &#8221;&#8217;Constructor&#8221;&#8217; #html header self.htmlHeader = &#8220;&lt;!DOCTYPE html&gt;&lt;html lang=\\&#8221;en\\&#8221;&gt;&lt;head&gt;&lt;meta charset=\\&#8221;utf-8\\&#8221;&gt;&lt;title&gt;iTunes Albums&lt;\/title&gt;&lt;!&#8211;[if lt IE 9]&gt;&lt;script src=\\&#8221;http:\/\/html5shim.googlecode.com\/svn\/trunk\/html5.js\\&#8221;&gt;&lt;\/script&gt;&lt;![endif]&#8211;&gt;&lt;\/head&gt;&lt;body&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Album&lt;\/th&gt;&lt;th&gt;Artiest&lt;\/th&gt;&lt;th&gt;Year&lt;\/th&gt;&lt;\/tr&gt;&#8221; #empty content, content is created with generateHTMLContent() self.htmlContent = &#8220;&#8221; #html footer self.htmlFooter = &#8220;&lt;\/tbody&gt;&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;&#8221; self.albumList = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1102,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>iTunes Library Parser - TableGenerator &ndash; DenBeke<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/denbeke.be\/blog\/itunes-library-parser\/itunes-library-parser-tablegenerator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"iTunes Library Parser - TableGenerator &ndash; DenBeke\" \/>\n<meta property=\"og:description\" content=\"class TableGenerator: &#039;&#039;&#039;Class for generating a HTML file with a list of albums. Input comes from iTune Library XML file&#039;&#039;&#039; def __init__(self, input_file, output_file): &#039;&#039;&#039;Constructor&#039;&#039;&#039; #html header self.htmlHeader = &quot;&lt;!DOCTYPE html&gt;&lt;html lang=\\&quot;en\\&quot;&gt;&lt;head&gt;&lt;meta charset=\\&quot;utf-8\\&quot;&gt;&lt;title&gt;iTunes Albums&lt;\/title&gt;&lt;!--[if lt IE 9]&gt;&lt;script src=\\&quot;http:\/\/html5shim.googlecode.com\/svn\/trunk\/html5.js\\&quot;&gt;&lt;\/script&gt;&lt;![endif]--&gt;&lt;\/head&gt;&lt;body&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Album&lt;\/th&gt;&lt;th&gt;Artiest&lt;\/th&gt;&lt;th&gt;Year&lt;\/th&gt;&lt;\/tr&gt;&quot; #empty content, content is created with generateHTMLContent() self.htmlContent = &quot;&quot; #html footer self.htmlFooter = &quot;&lt;\/tbody&gt;&lt;\/table&gt;&lt;\/body&gt;&lt;\/html&gt;&quot; self.albumList = [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/itunes-library-parser\/itunes-library-parser-tablegenerator\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"1 minute\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/denbeke.be\/blog\/#website\",\"url\":\"https:\/\/denbeke.be\/blog\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/denbeke.be\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/itunes-library-parser\/itunes-library-parser-tablegenerator\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/itunes-library-parser\/itunes-library-parser-tablegenerator\/\",\"name\":\"iTunes Library Parser - TableGenerator &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"datePublished\":\"2013-03-13T18:53:58+00:00\",\"dateModified\":\"2013-03-13T18:53:58+00:00\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/itunes-library-parser\/itunes-library-parser-tablegenerator\/\"]}]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/pages\/1120"}],"collection":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/comments?post=1120"}],"version-history":[{"count":1,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/pages\/1120\/revisions"}],"predecessor-version":[{"id":1121,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/pages\/1120\/revisions\/1121"}],"up":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/pages\/1102"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=1120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}