{"id":618,"date":"2010-08-31T14:26:18","date_gmt":"2010-08-31T14:26:18","guid":{"rendered":"http:\/\/www.nostuff.org\/words\/2010\/talis-aspire-checking-if-a-course-has-a-list\/"},"modified":"2010-08-31T14:26:18","modified_gmt":"2010-08-31T14:26:18","slug":"talis-aspire-checking-if-a-course-has-a-list","status":"publish","type":"post","link":"https:\/\/www.nostuff.org\/words\/2010\/talis-aspire-checking-if-a-course-has-a-list\/","title":{"rendered":"Talis Aspire, checking if a course has a list"},"content":{"rendered":"<p><a href=\"http:\/\/www.talis.com\/aspire\/\" target=\"_blank\">Talis Aspire<\/a> is a new-ish Reading List system used at the University of Sussex Library.<\/p>\n<p>On Aspire, a url for a <em>Department<\/em> looks like this:<br \/>\n<a href=\"http:\/\/liblists.sussex.ac.uk\/departments\/anthropology.html\">http:\/\/liblists.sussex.ac.uk\/departments\/anthropology.html<\/a><\/p>\n<p>A page for a <em>course<\/em> looks like this (for course l6061):<br \/>\n<a href=\"http:\/\/liblists.sussex.ac.uk\/courses\/l6061.html\">http:\/\/liblists.sussex.ac.uk\/courses\/l6061.html<\/a><\/p>\n<p>The <a href=http:\/\/092.me>nice<\/a> thing is that you can replace the \u2018.html\u2019 with <a href=\"http:\/\/liblists.sussex.ac.uk\/courses\/l6061.json\" target=\"_blank\">.json<\/a> or <a href=\"http:\/\/liblists.sussex.ac.uk\/courses\/l6061.rdf\" target=\"_blank\">.rdf<\/a> \u2013 while the html only has a link to the related list, the json and rdf expose other links and relationships, such as the department.<\/p>\n<p>For us, most (but not all) courses only have one list. URLs for lists are not predictable in the same way as the courses URL. E.g.<br \/>\n<a href=\"http:\/\/liblists.sussex.ac.uk\/lists\/EEC1E2AA-C350-DAFC-BDE4-1E9EF5EC69E5.html\">http:\/\/liblists.sussex.ac.uk\/lists\/EEC1E2AA-C350-DAFC-BDE4-1E9EF5EC69E5.html<\/a><\/p>\n<p><!--more-->So what if you want to link to a list from an external system.<\/p>\n<p>The University has a portal which includes for students a list of their courses and provides a link to those that have a reading list. Two issues: it needs to know which courses have a reading list on Talis Aspire, and it needs a way to link to them.<\/p>\n<p><a href=\"http:\/\/151.236.222.184\/words\/wp-content\/uploads\/2010\/08\/sussexdirect1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border: 0px;\" title=\"Sussex Direct, links to reading lists\" src=\"http:\/\/151.236.222.184\/words\/wp-content\/uploads\/2010\/08\/sussexdirect_thumb1.png\" border=\"0\" alt=\"Sussex Direct, links to reading lists\" width=\"644\" height=\"193\" \/><\/a><\/p>\n<p>The easiest way to achieve the former is for the central admin\/portal server to query (make a http request) for each course provided by the University, if it gets a 404, no list exists for that course. It can then flag each course that has a list (using a field in the database).<\/p>\n<p>And what about linking to a list. We actually have three options. The first is to simply link to the course link above (second link from the top), this will show any lists for that course, but will normally require the user to click on the single reading list link to see the list items, which isn\u2019t ideal. The second method is to process the json data in the step above (where we were checking for the existence of a course page), the data will include the URL for the list(s) which could then be stored in the portal DB.<\/p>\n<p>But the third option is the easiest. Turns out there is a <a href=http:\/\/092.me>nice<\/a> URL you can use, similar to the one above, which will take the user directly to a list for a course, if there is only one, if there is more than more it will show a list (of, ummm, lists) instead, and this URL is predictable for any given course code.<\/p>\n<p>Here\u2019s an example of both scenarios. Thanks for Chris Clarke at Talis for the information on this.<\/p>\n<p><a href=\"http:\/\/liblists.sussex.ac.uk\/courses\/l6061\/lists.html\">http:\/\/liblists.sussex.ac.uk\/courses\/l6061\/lists.html<\/a> [one list, norm]<br \/>\n<a href=\"http:\/\/liblists.sussex.ac.uk\/courses\/v1367\/lists.html\">http:\/\/liblists.sussex.ac.uk\/courses\/v1367\/lists.html<\/a> (<a href=\"http:\/\/liblists.sussex.ac.uk\/courses\/v1367\/lists.json\" target=\"_blank\">json<\/a>) [two lists]<\/p>\n<p>Finally, I knocked up some bad php to demonstrate this. It queries the url above, and returns either the urls of the list(s) or a message to say there is no course or lists for that course code.<\/p>\n<p><a href=\"http:\/\/www.lib.sussex.ac.uk\/coursechecker.php?course=v1367\">http:\/\/www.lib.sussex.ac.uk\/coursechecker.php?course=v1367<\/a><br \/>\n<a href=\"http:\/\/www.lib.sussex.ac.uk\/coursechecker.php?course=l6066\">http:\/\/www.lib.sussex.ac.uk\/coursechecker.php?course=l6066<\/a><br \/>\n<a href=\"http:\/\/www.lib.sussex.ac.uk\/coursechecker.php?course=abc\">http:\/\/www.lib.sussex.ac.uk\/coursechecker.php?course=abc<\/a> [doesn\u2019t exist]<\/p>\n<blockquote><p>&lt;?php<\/p>\n<p># This script is past a course code<br \/>\n# it returns any reading lists attached to that coursecode<\/p>\n<p>$baseurl = &#8220;<a href=\"http:\/\/liblists.sussex.ac.uk&quot;;\">http:\/\/liblists.sussex.ac.uk&#8221;;<\/a><\/p>\n<p>$coursecode = $_GET[&#8220;course&#8221;];<br \/>\nif ($coursecode == &#8220;&#8221; OR $coursecode == null) {<br \/>\necho &#8220;no course&#8221;;<br \/>\nexit;<br \/>\n}<\/p>\n<p># this url will exist if there are lists for this course,<br \/>\n# and will not exist (404) if there are not<br \/>\n$url = $baseurl . &#8220;\/courses\/&#8221; . $coursecode . &#8220;\/lists.json&#8221;;<br \/>\n# &#8230;also available in html and rdf<\/p>\n<p># Get webpage using curl<br \/>\n$ch\u00a0\u00a0\u00a0\u00a0\u00a0 = curl_init( $url );<br \/>\n# OPTION: don&#8217;t put it on screen<br \/>\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br \/>\n$page = curl_exec($ch);<br \/>\n$header\u00a0 = curl_getinfo( $ch );<br \/>\ncurl_close($ch);<br \/>\n$statuscode = $header[&#8216;http_code&#8217;];<\/p>\n<p># if status code 404 then no page<br \/>\nif ($statuscode == &#8216;404&#8217;) {<br \/>\necho &#8216;NOREADINGLIST&#8217;;<br \/>\n}<\/p>\n<p># we have a page for this course<br \/>\nelseif ($statuscode == &#8216;200&#8217;) {<br \/>\n# use json to return url to list(s), though if only one the original url,<br \/>\n# ending in html, will take you to it.<br \/>\nget_list_url($page);<br \/>\n}<\/p>\n<p># or maybe we have another status code<br \/>\nelse {<br \/>\necho &#8216;NOTSURE&#8217;;<br \/>\n}<\/p>\n<p>function get_list_url ($page) {<br \/>\n# JSON<br \/>\n$data = json_decode($page, true); #true=array<\/p>\n<p>foreach ($data as $listurl =&gt; $stuff) {<br \/>\n# we only want lists. not courses or departments<br \/>\nif (preg_match(&#8220;\/\/lists\/\/&#8221;, $listurl)) {<br \/>\necho &#8220;$listurl&lt;br&gt;n&#8221;;<br \/>\n}<br \/>\n}<\/p>\n<p>}<\/p>\n<p>?&gt;<\/p><\/blockquote>\n<p>So once a week, the central portal will query Talis Aspire for each course to see if there is a reading list, and store the result. And it will link to lists using the URL <a href=\"http:\/\/liblists.sussex.ac.uk\/courses\/{coursecode}\/lists.html\">http:\/\/liblists.sussex.ac.uk\/courses\/{coursecode}\/lists.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Talis Aspire is a new-ish Reading List system used at the University of Sussex Library. On Aspire, a url for a Department looks like this: http:\/\/liblists.sussex.ac.uk\/departments\/anthropology.html A page for a course looks like this (for course l6061): http:\/\/liblists.sussex.ac.uk\/courses\/l6061.html The nice thing is that you can replace the \u2018.html\u2019 with .json or .rdf \u2013 while the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[25,45,87,140,176],"class_list":["post-618","post","type-post","status-publish","format-standard","hentry","category-code","category-information-searching-and-libraries","tag-aspire","tag-curl","tag-json","tag-php","tag-talis"],"_links":{"self":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/posts\/618","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/comments?post=618"}],"version-history":[{"count":0,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/posts\/618\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/media?parent=618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/categories?post=618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nostuff.org\/words\/wp-json\/wp\/v2\/tags?post=618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}