We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi , I've made a sketch to Fetch data from RSS Feed and save them in PNG format , Now I want to add interval to be able to fetch every 5 minutes , can any one help me with the code :
PGraphics pg;
String[] titles;
PFont font;
int rows = 7 ;
void setup() {
pg = createGraphics(1280 , 720 );
size(1280, 720);
pg.smooth();
}
void draw() {
xmlparse();
pg.beginDraw();
PFont f = createFont("Nazanin", 48);
pg.textFont(f, 48);
// Draw all titles with bars and colors depending on its length
for (int i = 0; i < rows ; i++) {
float y = (i+1) * 65;
pg.fill(0);
pg.text(titles[i], width - 5, y);
pg.textAlign(RIGHT , TOP);
}
pg.endDraw();
image(pg, 0, 0, width, height);
pg.save("news.png");
}
void xmlparse(){
// Load RSS feed
String url = "http://www.hamshahrionline.ir/rss";
XML rss = loadXML(url);
// Get title of each element
XML[] titleXMLElements = rss.getChildren("channel/item/title");
titles = new String[titleXMLElements.length];
for (int i = 0; i < rows ; i++) {
String title = titleXMLElements[i].getContent();
// Store title in array for later use
titles[i] = title;
}
}
Answers
What about setting a separate Thread w/ the task to retrieve RSS data within a delay(INTERVAL)? *-:)
Introducing Processing's hidden & unofficial function -> thread("")! =D>
With that, we can call a defined function within our sketch as an independent running Thread!
I've also made lotsa tweaks to your code. Check it out: ;;)
Wow ! Thanx Man Your a Life saver :)