Author Topic: RSS Challenge  (Read 1453 times)

Offline AIR

  • BASIC Developer
  • Posts: 817
RSS Challenge
« on: August 14, 2021, 08:57:31 pm »
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 format
Speed 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
--------------------

AIR.

Offline AIR

  • BASIC Developer
  • Posts: 817
Re: RSS Challenge
« Reply #1 on: August 14, 2021, 09:08:05 pm »
NIM Code by AIR:
Code: Text
  1. import httpClient
  2. import xmlparser
  3. import xmltree
  4. import strutils
  5. from parseutils import parseInt
  6. from strformat import fmt
  7.  
  8.  
  9. var url = "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high"
  10.  
  11. proc secondsToHMS(seconds: string): string =
  12.     var totalSeconds = seconds.parseInt
  13.     var seconds = totalSeconds.mod(60)
  14.     var minutes = (totalSeconds.mod(3600)).div(60)
  15.     var hours = (totalSeconds.mod(86400)).div(3600)
  16.     result = fmt"{hours:02}:{minutes:02}:{seconds:02}"
  17.  
  18.  
  19. proc fetchRSS(url: string): XmlNode =
  20.     var client = newHttpClient()
  21.     let rss = client.getContent(url)
  22.     return parseXML(rss)
  23.  
  24.  
  25. var xmlRoot = fetchRSS(url)
  26. echo "-".repeat(20)
  27. for item in xmlRoot.findAll("item"):
  28.     echo "Title: " & item.child("title").innerText
  29.     echo "Presenter: " & item.child("dc:creator").innerText
  30.     echo "Date: " & item.child("pubDate").innerText
  31.     echo "Description: " & item.child("itunes:summary").innerText
  32.     echo "Video Link: " & item.child("enclosure").attr("url")
  33.     echo "Duration: " & secondsToHMS(item.child("media:group").child("media:content").attr("duration"))
  34.     echo "-".repeat(20)
  35.  

AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3115
    • ScriptBasic Open Source Project
Re: RSS Challenge
« Reply #2 on: August 14, 2021, 09:15:04 pm »
Great idea AIR. Let's hope this wakes up the member base.

I'll submit a SB version soon.

Offline John

  • Forum Support / SB Dev
  • Posts: 3115
    • ScriptBasic Open Source Project
Re: RSS Challenge
« Reply #3 on: August 14, 2021, 11:14:24 pm »
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
  1. IMPORT curl.sbi
  2.  
  3. ch = curl::init()
  4. curl::option(ch, "URL", "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high")
  5. curl::option(ch, "FILE", "mp4high.xml")
  6. curl::perform(ch)
  7. curl::finish(ch)
  8.  

Code: Script BASIC
  1. IMPORT curl.sbi
  2.  
  3. ch = curl::init()
  4. curl::option(ch, "URL", "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high")
  5. curl::option(ch, "CUSTOMREQUEST", "GET")
  6. rss = curl::perform(ch)
  7. curl::finish(ch)
  8.  
  9. PRINT rss
  10.  

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
  1. OPEN "channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high:80" FOR socket AS #1
  2.  
  3. FOR x = 1 to 50
  4.   LINE INPUT #1, rss
  5.   PRINT rss
  6. NEXT
  7.  
  8. CLOSE(1)
  9.  


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

« Last Edit: August 14, 2021, 11:50:12 pm by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3115
    • ScriptBasic Open Source Project
Re: RSS Challenge
« Reply #4 on: August 15, 2021, 12:08:53 am »
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
  1. ubuntu@rpi4b:~/sbrt/examples$ scriba rss.sb
  2. <html><head><title>Object moved</title></head><body>
  3. <h2>Object moved to <a href="https://s.ch9.ms/Events/MIX/MIX11/RSS/mp4high">here</a>.</h2>
  4. </body></html>
  5. ubuntu@rpi4b:~/sbrt/examples$
  6.  

The Windows version is returning an extension module error using HTTPS.  :-\

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



Offline John

  • Forum Support / SB Dev
  • Posts: 3115
    • ScriptBasic Open Source Project
Re: RSS Challenge
« Reply #5 on: August 15, 2021, 02:16:09 am »
Code: Script BASIC
  1. ' AIR RSS Challenge
  2.  
  3. IMPORT curl.bas
  4.  
  5. ch = curl::init()
  6. curl::option(ch, "URL", "https://s.ch9.ms/Events/MIX/MIX11/RSS/mp4high")
  7. rss = curl::perform(ch)
  8. curl::finish(ch)
  9.  
  10. SPLITA rss BY "</item>" TO item
  11. FOR x = 0 TO UBOUND(item)
  12.   IF item[x] LIKE "*<title>*</title>*[CDATA[<p>*</p>*<pubDate>*</pub*<dc:creator>*</dc:*<enclosure url=\"*\" length*duration=\"*\"*" THEN
  13.     PRINT STRING(20,"-"), "\n"
  14.     PRINT "Title: ", JOKER(2), "\n"
  15.     PRINT "Presenter: ",JOKER(8), "\n"
  16.     PRINT "Date: ", JOKER(6), "\n"
  17.     PRINT "Description: ", JOKER(4), "\n"
  18.     PRINT "Video Link: ", JOKER(10), "\n"
  19.     PRINT "Duration: ", FORMATDATE("0H:0m:0s", JOKER(12)), "\n"
  20.   END IF
  21. NEXT
  22.  


--------------------
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&rsquo;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&rsquo;ll look at geolocation at every layer of the stack &ndash; 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&rsquo;s location and then delve into how to make geo data a useful addition to your application instead of a bolt-on &ldquo;me too&rdquo;.
Video Link: http://video.ch9.ms/ch9/7ce8/f849553d-644e-4dad-8deb-9ea700dd7ce8/MIX11EXT04_high_ch9.mp4
Duration: 00:47:52

Offline AIR

  • BASIC Developer
  • Posts: 817
Re: RSS Challenge
« Reply #6 on: August 15, 2021, 10:41:14 am »
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
  1. ubuntu@rpi4b:~/sbrt/examples$ scriba rss.sb
  2. <html><head><title>Object moved</title></head><body>
  3. <h2>Object moved to <a href="https://s.ch9.ms/Events/MIX/MIX11/RSS/mp4high">here</a>.</h2>
  4. </body></html>
  5. ubuntu@rpi4b:~/sbrt/examples$
  6.  

The Windows version is returning an extension module error using HTTPS.  :-\

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

The redirect is a wrinkle/easter egg.  ;)

Try the "CURLOPT_FOLLOWLOCATION" option?

AIR.

Offline John

  • Forum Support / SB Dev
  • Posts: 3115
    • ScriptBasic Open Source Project
Re: RSS Challenge
« Reply #7 on: August 19, 2021, 06:55:03 am »
Here is the final SB submission using your original URL. Running on Windows 10 Pro.

Code: Script BASIC
  1. ' AIR RSS Challenge
  2.  
  3. IMPORT curl.sbi
  4.  
  5. ch = curl::init()
  6. curl::option(ch, "URL", "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high")
  7. curl::option(ch, "FOLLOWLOCATION")
  8. rss = curl::perform(ch)
  9. curl::finish(ch)
  10.  
  11. SPLITA rss BY "</item>" TO item
  12. FOR x = 0 TO UBOUND(item)
  13.   IF item[x] LIKE "*<title>*</title>*[CDATA[<p>*</p>*<pubDate>*</pub*<dc:creator>*</dc:*<enclosure url=\"*\" length*duration=\"*\"*" THEN
  14.     PRINT STRING(20,"-"), "\n"
  15.     PRINT "Title: ", JOKER(2), "\n"
  16.     PRINT "Presenter: ",JOKER(8), "\n"
  17.     PRINT "Date: ", JOKER(6), "\n"
  18.     PRINT "Description: ", JOKER(4), "\n"
  19.     PRINT "Video Link: ", JOKER(10), "\n"
  20.     PRINT "Duration: ", FORMATDATE("0H:0m:0s", JOKER(12)), "\n"
  21.   END IF
  22. NEXT
  23.  

Offline AIR

  • BASIC Developer
  • Posts: 817
Re: RSS Challenge
« Reply #8 on: August 19, 2021, 03:14:34 pm »
Powershell (works on both my PC and Mac)

Code: PowerShell
  1. $sep = "-" * 20
  2.  
  3. [xml]$Content = (Invoke-WebRequest -Uri "http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high").Content
  4.  
  5. echo $sep
  6. foreach ($item in $Content.rss.channel.item) {
  7.     echo ("Title: " + $item.title)
  8.     echo ("Presenter: " + $item.creator)
  9.     echo ("Date: " + $item.pubDate)
  10.     echo ("Description: " + $item.summary)
  11.     echo ("Video Link: " + $item.enclosure.url)
  12.     echo ("Duration: " + [timespan]::fromseconds($item.duration).tostring("hh\:mm\:ss") )
  13.     echo $sep
  14. }


Code: [Select]
--------------------
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&rsquo;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&rsquo;ll look at geolocation at every layer of the stack &ndash; 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&rsquo;s location and then delve into how to make geo data a useful addition to your application instead of a bolt-on &ldquo;me too&rdquo;.
Video Link: http://video.ch9.ms/ch9/7ce8/f849553d-644e-4dad-8deb-9ea700dd7ce8/MIX11EXT04_high_ch9.mp4
Duration: 00:47:52
--------------------
Title: Flickr API: Tap Into Billions of Photos for Windows Phone 7
Presenter: Markus Spiering
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: Do you want your app to integrate with one of the world&rsquo;s leading photosharing site? The Flickr for Windows Phone 7 app is a full featured mobile application that is pushing the boundaries of UX design and is 100% built on Flickr's API methods that are available for developers. This talk will introduce the mobile app, highlight some of the complex design decisions, and provide insights into the Flickr API methods. Attendees will learn how to enrich their applications using Flickr's rich content via the Flickr APIs.
Video Link: http://video.ch9.ms/ch9/7BAE/1F7A8CCB-5580-47BF-9371-9EA700DD7BAE/MIX11EXT01_high_ch9.mp4
Duration: 00:50:32
--------------------
Title: Fonts, Form and Function: A Primer on Digital Typography
Presenter: Robby Ingebretsen
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: Typography in digital experiences is unavoidable, and for years it was a fight we mostly lost. Today, however, technology is on our side! High resolution screens, an expanding library of open fonts and new flexibility in nearly every UI technology have made digital typography more fun and more interesting than ever. We'll cover all aspects of working with digital type: everything from choosing complimentary typefaces to licensing, rendering and a system for layout and sizing. We all love type. Come to this talk to learn why!
Video Link: http://video.ch9.ms/ch9/7bc8/133b3b99-1949-4ef4-a27c-9ec6010c7bc8/MIX11EXT02_high_ch9.mp4
Duration: 01:03:27
--------------------

Offline John

  • Forum Support / SB Dev
  • Posts: 3115
    • ScriptBasic Open Source Project
Re: RSS Challenge
« Reply #9 on: August 19, 2021, 03:45:44 pm »
Nice!

I use PowerShell as my SSH client on Windows.

Offline AIR

  • BASIC Developer
  • Posts: 817
Re: RSS Challenge
« Reply #10 on: August 19, 2021, 05:02:37 pm »
Last one.

PYTHON

Code: Python
  1. #!/usr/bin/env python3
  2.  
  3. import feedparser
  4. from datetime import timedelta
  5.  
  6. d = feedparser.parse("http://channel9.msdn.com/Events/MIX/MIX11/RSS/mp4high")
  7.  
  8. for x in d.entries:
  9.     print ("Title: " + x.title)
  10.     print ("Presentor: " + x.author)
  11.     print ("Date: " + x.published)
  12.     print ("Description: " + x.summary.split("</p>")[0].replace("<p>",""))
  13.     print ("Video Link: " + x.media_content[0]['url'])
  14.     print ("Duration: " + "{}".format(str(timedelta(seconds=int(x.media_content[0]['duration'])))))
  15.     print ('-' * 20)
  16.  

Code: [Select]
--------------------
Title: Riding the Geolocation Wave
Presentor: Tatham Oddie
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: It&rsquo;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&rsquo;ll look at geolocation at every layer of the stack &ndash; 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&rsquo;s location and then delve into how to make geo data a useful addition to your application instead of a bolt-on &ldquo;me too&rdquo;.
Video Link: http://files.ch9.ms/mix/2011/mp4/EXT04.mp4
Duration: 0:47:52
--------------------
Title: Flickr API: Tap Into Billions of Photos for Windows Phone 7
Presentor: Markus Spiering
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: Do you want your app to integrate with one of the world&rsquo;s leading photosharing site? The Flickr for Windows Phone 7 app is a full featured mobile application that is pushing the boundaries of UX design and is 100% built on Flickr's API methods that are available for developers. This talk will introduce the mobile app, highlight some of the complex design decisions, and provide insights into the Flickr API methods. Attendees will learn how to enrich their applications using Flickr's rich content via the Flickr APIs.
Video Link: http://files.ch9.ms/mix/2011/mp4/EXT01.mp4
Duration: 0:50:32
--------------------
Title: Fonts, Form and Function: A Primer on Digital Typography
Presentor: Robby Ingebretsen
Date: Tue, 15 Mar 2011 20:26:00 GMT
Description: Typography in digital experiences is unavoidable, and for years it was a fight we mostly lost. Today, however, technology is on our side! High resolution screens, an expanding library of open fonts and new flexibility in nearly every UI technology have made digital typography more fun and more interesting than ever. We'll cover all aspects of working with digital type: everything from choosing complimentary typefaces to licensing, rendering and a system for layout and sizing. We all love type. Come to this talk to learn why!
Video Link: http://files.ch9.ms/mix/2011/mp4/EXT02.mp4
Duration: 1:03:27
--------------------

AIR.