BASIC User Group > Code Challenges

RSS Challenge

(1/3) > >>

AIR:
Don't know if we're still doing this since it's been a while.


Using the rss feed "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high", which is a series of MSDN-sponsored video presentations, download and parse the feed (a local copy of the rss is not allowed for your final submission, but can be used only while building out your submission) and produce output that shows:

* Title
* Name of Presenter
* The Release Date
* Description of the Video Presentation
* Link to the video itself
* Duration of the Video in HH:MM:SS formatSpeed is not the point, accuracy is, since people have different internet capabilities (and some of you may be international).

External libraries are allowed.  External executables/binaries are not (so no curl, xpath, or any other command line tool), because the spirit of this challenge is to provide a solution in code leveraging what your language of choice provides you with.


Example output, generated by code I created this evening using NIM:


--- Quote -----------------------
Title: Introducing MMP Audience Insight
Presenter: Eric Schmidt
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: As live and on-demand online video distribution grows so does the need for meaningful and timely analysis of consumption and quality of service. Microsoft Media Platform Audience Insight is a composeable collection of technologies that enables media publishers, application developers, business decision makers and technical support staff to gain real time insight to media streaming applications. Audience Insight provides real time visibility into digital media related events, for example video starts, DVR actions and advertising delivery. These events are correlated and grouped to produce sets of KPIs to inform real time decision making and contextual business analysis. This session will review the architecture behind Audience Insight and will demonstrate how to gain insight for massive scale video distribution scenarios.
Video Link: http://video.ch9.ms/ch9/7e2b/82589c56-4005-405d-959e-9ea700dd7e2b/MIX11MED04_high_ch9.mp4
Duration: 01:02:48
--------------------
Title: Mono: State of the Union
Presenter: Miguel de Icaza
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: Come learn how Mono can help every one of your current projects: from our C# compiler as a service to running your .NET code on iPhone, Android and Mac. All demos will feature our amazing MonoDevelop cross platform IDE. Come to be energized and fall in love with .NET all over again. This is your second honeymoon. Do not miss it.
Video Link: http://video.ch9.ms/ch9/7c8b/2d17abeb-01a7-4d61-b366-9ea700dd7c8b/MIX11EXT03_high_ch9.mp4
Duration: 01:05:05
--------------------
Title: Riding the Geolocation Wave
Presenter: Tatham Oddie
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: It’s pretty obvious by now that geolocation is a heavy player in the next wave of applications and APIs. Now is the time to learn how to take advantage of this information and add context to your own applications. In this session we’ll look at geolocation at every layer of the stack – from open protocols to operating system APIs, from the browser to Windows Phone 7. Building a compelling geo-enabled experience takes more than simple coordinates. In this session we will introduce the basics of determining a user’s location and then delve into how to make geo data a useful addition to your application instead of a bolt-on “me too”.
Video Link: http://video.ch9.ms/ch9/7ce8/f849553d-644e-4dad-8deb-9ea700dd7ce8/MIX11EXT04_high_ch9.mp4
Duration: 00:47:52
--------------------
--- End quote ---

AIR.

AIR:
NIM Code by AIR:

--- Code: Text ---import httpClientimport xmlparserimport xmltreeimport strutilsfrom parseutils import parseIntfrom strformat import fmt  var url = "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high" proc secondsToHMS(seconds: string): string =    var totalSeconds = seconds.parseInt    var seconds = totalSeconds.mod(60)    var minutes = (totalSeconds.mod(3600)).div(60)    var hours = (totalSeconds.mod(86400)).div(3600)    result = fmt"{hours:02}:{minutes:02}:{seconds:02}"  proc fetchRSS(url: string): XmlNode =    var client = newHttpClient()    let rss = client.getContent(url)    return parseXML(rss)  var xmlRoot = fetchRSS(url)echo "-".repeat(20)for item in xmlRoot.findAll("item"):    echo "Title: " & item.child("title").innerText    echo "Presenter: " & item.child("dc:creator").innerText    echo "Date: " & item.child("pubDate").innerText    echo "Description: " & item.child("itunes:summary").innerText    echo "Video Link: " & item.child("enclosure").attr("url")    echo "Duration: " & secondsToHMS(item.child("media:group").child("media:content").attr("duration"))    echo "-".repeat(20) 
AIR.

John:
Great idea AIR. Let's hope this wakes up the member base.

I'll submit a SB version soon.

John:
Strange I can't seem to download / GET the file with the ScriptBasic cURL extension module. When I try the URL in a browser it asks how I want to view the file.

No error  but no data returned either.


--- Code: Script BASIC ---IMPORT curl.sbi ch = curl::init()curl::option(ch, "URL", "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high")curl::option(ch, "FILE", "mp4high.xml")curl::perform(ch)curl::finish(ch) 

--- Code: Script BASIC ---IMPORT curl.sbi ch = curl::init()curl::option(ch, "URL", "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high")curl::option(ch, "CUSTOMREQUEST", "GET")rss = curl::perform(ch)curl::finish(ch) PRINT rss 
Neither of the above examples return anything.  :-[  SB Linux does the same thing.

I tried using the SB native socket feature but it can't open the file either.


--- Code: Script BASIC ---OPEN "channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high:80" FOR socket AS #1 FOR x = 1 to 50  LINE INPUT #1, rss  PRINT rssNEXT CLOSE(1) 

(0): error &H16:The file can not be opened.

John:
I was able to open the file with the cURL extension module using HTTPS. Your example uses HTTP The URL you used is redirected.


--- Code: Bash ---ubuntu@rpi4b:~/sbrt/examples$ scriba rss.sb<html><head><title>Object moved</title></head><body><h2>Object moved to <a href="https://s.ch9.ms/Events/MIX/MIX11/RSS/mp4high">here</a>.</h2></body></html>ubuntu@rpi4b:~/sbrt/examples$ 
The Windows version is returning an extension module error using HTTPS.  :-\

I will have to do the challenge in SB Linux. (RPi 4B)


Navigation

[0] Message Index

[#] Next page

Go to full version