Award
Congratulations CochranRobotics, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Two Questions Regarding Rss Feed Scripts

Assistance Requested

Help Steve G with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

Steve G claims to have checked these sources:
 
#1

Hi guys.

I need a little help with an RSS feed script and hoping someone can point me in the right direction.

Question one.

Is there a way to have an RSS feed to be spoken through the EZB4 instead of through the PC's sound card as I haven't seen a "SpeakRSSEZB() script function?

Question 2.

I am looking for a way to insert something similar to a "Sleep()" function in-between each RSS feed in the script below with a 2 second gap between each feed read.

Code:


SpeakRSS("http://feeds.skynews.com/feeds/rss/uk.xml",1)
SpeakRSS("http://feeds.skynews.com/feeds/rss/uk.xml",2)
SpeakRSS("http://feeds.skynews.com/feeds/rss/uk.xml",3)
SpeakRSS("http://feeds.skynews.com/feeds/rss/uk.xml",4)



The "Sleep() script function is not a viable option as the length of the feeds spoken change length from day to day (or hour to hour) so I need something like a "SayWait() but not sure what or where to put the correct function in to my script.

Many thanks.

Steve G. Smile

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

Well I have spent some time and gone through the entire script command menu, but have not seen a command that will "speak" an RSS feed through the EZ-B v4's speaker, only through my PC's speakers. Is there a way to do this, and if not, can this be an EZ-Builder feature request? *confused*

Thanks.

#3

That's because speak RSSEZB hasn't been added yet... Not sure if it will be added... Maybe it will at some point....

#4

When I wrote "Speak RSSEZB()" it was just example of what I wanted to accomplish Winky. Hopefully DJ will consider adding this feature if there's no other way. It would be a great addition.

#5

@EZ-Robot team.

Hi guys. I would like to mark this thread as resolved so can I ask, has adding the ability to have an RSS feed to be heard through the EZ-B4 speaker been added to the "to do" list for EZ-Builder for a future release?

@everybody else

Has anyone found a way to achieve this with some cleaver scripting? I have had a little play around with scripts but been unable to get it to work.

Thanks. Smile

#6

You could use scripting but the SpeakRSS() command doesn't save the results to a variable, you would need to use HTTPGet() and parse the returned results. Such a simple task is a fair amount of scripting (so I've not even looked at doing it).

#7

I have written an exe In c# that gets all of my rss feeds for the day and places them into text files on my computer. It also strip out the characters that cause issues when reading the rss feeds. In EZ-Builder, I read these files into variables. I haven't tried it yet, but you should be able to then use the variable in a speakezb command. I am in the middle of a crisis at work right now. I will post the code for the exe later today when I have time to find it.

#8

It has been a while since I looked at this, but here is a good sample to start with.

This build a file at "C:\rssfeeds\Bible.txt" and uses "http://feeds.feedburner.com/ESV-one-year-tract?format=xml"; for the feed.


Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using System.Text;

namespace BibleVerse
{
static class BibleVerse
{
/// <summary>
/// Used to convert RSS read to plain text file
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);


XmlDocument rssXmlDoc = new XmlDocument();
string nextline = null;

// Load the RSS file from the RSS URL
rssXmlDoc.Load("http://feeds.feedburner.com/ESV-one-year-tract?format=xml";);

// Parse the Items in the RSS file
XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");

StringBuilder rssContent = new StringBuilder();
System.IO.StreamWriter file = new System.IO.StreamWriter("C:\\rssfeeds\\Bible.txt");

// Iterate through the items in the RSS file
foreach (XmlNode rssNode in rssNodes)
{
XmlNode rssSubNode = rssNode.SelectSingleNode("title");
string title = rssSubNode != null ? rssSubNode.InnerText : "";

rssSubNode = rssNode.SelectSingleNode("link");
string link = rssSubNode != null ? rssSubNode.InnerText : "";

rssSubNode = rssNode.SelectSingleNode("description");
string description = rssSubNode != null ? rssSubNode.InnerText : "";
// Removes the &nbsp; characters - may not be needed
rssContent.Append(description.Replace("&nbsp;", ""));
// regex to turn html into text
nextline = System.Text.RegularExpressions.Regex.Replace(rssContent.ToString(), "<[^>]*>", "");
//replace whitespace
nextline = System.Text.RegularExpressions.Regex.Replace(nextline, "[\n\r\t]", " ");
nextline = nextline.Replace("\"","");
nextline = nextline.Replace("(","");
nextline = nextline.Replace(")", "");
nextline = nextline.Replace("&mdash;", "");
//int cutat = 0;
//cutat = nextline.IndexOf("Biography");
// nextline = nextline.Remove(cutat);
file.WriteLine(nextline);
break;

}
file.Close();


nextline = null;
//Application.Run(new Form1());
Application.Exit();
}

}
}





In EZ-Builder I have a script that reads the file into a variable called $rsstext and then uses the Say command to read the variable. This could be changed to the SAYEZB command.

After the reading is complete, it deletes the file and clears the variable to save memory and drive space.

Code:


#Run the app to get the poem
Exec("c:\rssfeeds\BibleVerse.exe")
Say("Retrieving the words of the almighty father for you sir.")
sleep(1000)
Say("Genesis, exodus, leviticus, numbers, oh here we are with todays verses")
#Load the poem into a variable
$rsstext = filereadline("C:\rssfeeds\Bible.txt")
#Read the poem
say($rsstext)
#Close the poem
filereadclose("C:\rssfeeds\Bible.txt")
#Delete the text and prepare for the next one
filedelete("C:\rssfeeds\Bible.txt")
#dump memory
$rsstext = ""




This way allows you to call the exe, which then generates the file on the fly. I had thought about making this database driven to allow you to store the RSS feed locations in a database, and then call them by ID instead of calling the exe.

In any event, it works. Using this the way it is now, you would have to create an exe for each feed, but that isnt hard and keeps you from making it too complicated in the long run. I like to complicate things so I am sure at some point in the future, I will make this database driven and store the text to the database for that day, and then update the variable from the database.

Let me know if you have any questions.

#9

I gave this one because it is impressive how much can be stored in a variable to be passed into the say command.

This part

Code:

 Say("Retrieving the words of the almighty father for you sir.")
sleep(1000)
Say("Genesis, exodus, leviticus, numbers, oh here we are with todays verses")



allows the executable time to get the feed and parse it without the robot sitting and acting like it is waiting for something (which it is).

#10

@d.cochran if you are outputting to the pc speakers using the say command should you use saywait instead?

Code:


SayWait("#text here")


that way you don't have to put the sleep in there...