<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tupil Code Blog &#187; upcoming</title>
	<atom:link href="http://blog.tupil.com/tag/upcoming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tupil.com</link>
	<description>(Get up early, code often)</description>
	<lastBuildDate>Fri, 27 Aug 2010 10:50:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A small mashup of Upcoming and Last.fm, in Haskell</title>
		<link>http://blog.tupil.com/a-small-mashup-of-upcoming-and-lastfm-in-haskell/</link>
		<comments>http://blog.tupil.com/a-small-mashup-of-upcoming-and-lastfm-in-haskell/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 12:06:56 +0000</pubDate>
		<dc:creator>Chris Eidhof</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[lastfm]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[upcoming]]></category>

		<guid isPermaLink="false">http://blog.tupil.com/?p=5</guid>
		<description><![CDATA[I wanted to play around with the recent XML and Curl libraries that were recently released by Galois, so I decided to write a mashup of Upcoming and Last.fm. In order for this code to run, you&#8217;ll also need to install the csv package for this. The code is relatively straightforward: fetch the top artists [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to play around with the recent <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xml">XML</a> and <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/curl">Curl</a> libraries that were recently released by <a href="http://galois.com/">Galois</a>, so I decided to write a mashup of <a href="http://upcoming.yahoo.com">Upcoming</a> and <a href="http://last.fm">Last.fm</a>. In order for this code to run, you&#8217;ll also need to install the <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/csv">csv</a> package for this.</p>
<p>The code is relatively straightforward: fetch the top artists for a given username, parse that csv-file, read the events in The Netherlands for every artist, and output every event. It works on the command line. Save this code as Upcoming.hs, then do <code>runhaskell Upcoming.hs chrisflip</code>, and replace <code>chrisflip</code> by your own last.fm username. </p>
<p>Enjoy!</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Network<span style="color: #339933; font-weight: bold;">.</span>Curl
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>CSV
<span style="color: #06c; font-weight: bold;">import</span> Network<span style="color: #339933; font-weight: bold;">.</span>CGI <span style="color: green;">&#40;</span>urlEncode<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>XML<span style="color: #339933; font-weight: bold;">.</span>Light
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Maybe</span> <span style="color: green;">&#40;</span>fromMaybe<span style="color: #339933; font-weight: bold;">,</span> fromJust<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Monad</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Environment <span style="color: green;">&#40;</span>getArgs<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- The top artists of last.fm</span>
url u <span style="color: #339933; font-weight: bold;">=</span> <span style="">&quot;http://ws.audioscrobbler.com/1.0/user/&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> u <span style="color: #339933; font-weight: bold;">++</span> <span style="">&quot;/topartists.txt&quot;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Upcomings's country_id for The Netherlands </span>
country<span style="color: #339933; font-weight: bold;">_</span>id <span style="color: #339933; font-weight: bold;">=</span> <span style="">&quot;9&quot;</span>
upcoming<span style="color: #339933; font-weight: bold;">_</span>url artist <span style="color: #339933; font-weight: bold;">=</span>  <span style="">&quot;http://upcoming.yahooapis.com/services/rest/?api_key=&quot;</span> 
                    <span style="color: #339933; font-weight: bold;">++</span> apikey <span style="color: #339933; font-weight: bold;">++</span> <span style="">&quot;&amp;method=event.search&amp;search_text=&quot;</span> 
                    <span style="color: #339933; font-weight: bold;">++</span> urlEncode artist <span style="color: #339933; font-weight: bold;">++</span> <span style="">&quot;&amp;country_id=&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> country<span style="color: #339933; font-weight: bold;">_</span>id
apikey <span style="color: #339933; font-weight: bold;">=</span> <span style="">&quot;ee395ae6dd&quot;</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
  <span style="color: green;">&#91;</span>username<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgs
  text <span style="color: #339933; font-weight: bold;">&lt;-</span> unsafeCurlGetString <span style="color: green;">&#40;</span>url username<span style="color: green;">&#41;</span>
  <span style="color: #06c; font-weight: bold;">let</span> <span style="color: green;">&#40;</span>Right a'<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> parseCSV <span style="color: green;">&#40;</span>url username<span style="color: green;">&#41;</span> text
      artists <span style="color: #339933; font-weight: bold;">=</span> getArtists a'
  <span style="font-weight: bold;">mapM_</span> getEvents artists
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- The artist is always in the 3rd column of the csv-file</span>
getArtists <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">!!</span> <span style="color: red;">2</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="font-weight: bold;">length</span> x <span style="color: #339933; font-weight: bold;">==</span> <span style="color: red;">3</span><span style="color: green;">&#41;</span>
&nbsp;
getEvents artist <span style="color: #339933; font-weight: bold;">=</span> unsafeCurlGetString <span style="color: green;">&#40;</span>upcoming<span style="color: #339933; font-weight: bold;">_</span>url artist<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> processArtist artist
&nbsp;
processArtist artist contents <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
  <span style="color: #06c; font-weight: bold;">let</span> eventEls <span style="color: #339933; font-weight: bold;">=</span> elChildren <span style="color: #339933; font-weight: bold;">$</span> fromJust <span style="color: #339933; font-weight: bold;">$</span> parseXMLDoc contents
  when <span style="color: green;">&#40;</span><span style="font-weight: bold;">length</span> eventEls <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="font-weight: bold;">putStrLn</span> artist
    <span style="font-weight: bold;">putStrLn</span> <span style="color: green;">&#40;</span>replicate <span style="color: green;">&#40;</span><span style="font-weight: bold;">length</span> artist<span style="color: green;">&#41;</span> '<span style="color: #339933; font-weight: bold;">-</span>'<span style="color: green;">&#41;</span>
    <span style="font-weight: bold;">mapM_</span> processEvent eventEls
    <span style="font-weight: bold;">putStrLn</span> <span style="">&quot;&quot;</span>
&nbsp;
processEvent evt <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">$</span> title <span style="color: #339933; font-weight: bold;">++</span> <span style="">&quot; @ &quot;</span> <span style="color: #339933; font-weight: bold;">++</span> location <span style="color: #339933; font-weight: bold;">++</span> <span style="">&quot; [&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> date <span style="color: #339933; font-weight: bold;">++</span> <span style="">&quot;]&quot;</span>
 <span style="color: #06c; font-weight: bold;">where</span> <span style="color: green;">&#91;</span>title<span style="color: #339933; font-weight: bold;">,</span> location<span style="color: #339933; font-weight: bold;">,</span> date<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">map</span> fa <span style="color: green;">&#91;</span><span style="">&quot;name&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="">&quot;venue_name&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="">&quot;start_date&quot;</span><span style="color: green;">&#93;</span>
       fa n <span style="color: #339933; font-weight: bold;">=</span> fromJust <span style="color: #339933; font-weight: bold;">$</span> findAttr <span style="color: green;">&#40;</span>unqual n<span style="color: green;">&#41;</span> evt
&nbsp;
unsafeCurlGetString url <span style="color: #339933; font-weight: bold;">=</span> curlGetString url <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">snd</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.tupil.com/a-small-mashup-of-upcoming-and-lastfm-in-haskell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
