Author: jorgediablu
Date: Sat Dec 6 10:22:06 2008
New Revision: 316
Added:
trunk/MailMan/Examples/Processing/FlickrBrowser/Flickr.pde
trunk/MailMan/Examples/Processing/FlickrBrowser/numerror.html
trunk/MailMan/Examples/Processing/FlickrBrowser/words.txt
Modified:
trunk/MailMan/Examples/Processing/FlickrBrowser/FlickrBrowser.pde
trunk/MailMan/Examples/Processing/FlickrBrowser/start.bat
Log:
[Mailman] FlickrBrowser example. Words are tested to see if they return
something. words are saved in file. added error messages.
Added: trunk/MailMan/Examples/Processing/FlickrBrowser/Flickr.pde
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/Flickr.pde Sat Dec 6
10:22:06 2008
@@ -0,0 +1,88 @@
+import proxml.*;
+
+String userName = "jorgecardoso";
+String apiKey = "b70f502524ffce22674e108aaf642180";
+String nsid = "";
+String url = "
http://api.flickr.com/services/rest/";
+XMLInOut xml = null;
+
+int num = -1;
+
+boolean search(String _n) {
+ num = -1;
+ String rest = url+"?method=flickr.photos.search";
+ rest += "&api_key=" + apiKey;
+ rest += "&text=" + _n;
+ xml.loadElement(rest);
+
+ for (int i = 0; i < 20; i++) {
+ if (num > 0) {
+ return true;
+ } else if (num == 0) {
+ return false;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ println(ie.getMessage());
+ }
+ }
+ return false;
+}
+
+void findByUsername(String _n) {
+ String rest = url+"?method=flickr.people.findByUsername";
+ rest += "&api_key=" + apiKey;
+ rest += "&username=" + _n;
+ xml.loadElement(rest);
+}
+
+void getPublicPhotos(String _n) {
+ String rest = url+"?method=flickr.people.getPublicPhotos";
+ rest += "&api_key=" + apiKey;
+ rest += "&user_id=" + nsid;
+ xml.loadElement(rest);
+}
+
+void xmlEvent(proxml.XMLElement _x) {
+ parseXML(_x);
+}
+
+void parseXML(proxml.XMLElement _x) {
+ String stat = _x.getAttribute("stat");
+ if (!stat.equals("ok")) {
+ println("Error from Flickr");
+ println(_x);
+ return;
+ }
+ proxml.XMLElement node = _x.getChild(0);
+ String type = node.getName();
+ if (type.equals("user")) {
+ nsid = node.getAttribute("nsid");
+ //println(nsid);
+ getPublicPhotos(nsid);
+ }
+ else if (type.equals("photos")) {
+ num = node.countChildren();
+ //println(num);
+ //getPhotos(node);
+ }
+}
+
+void getPhotos(proxml.XMLElement _n) {
+ int cnt = _n.countChildren();
+ cnt = min(cnt,64);
+ for (int i=0;i<cnt;i++) {
+ proxml.XMLElement ph = _n.getChild(i);
+ String fm = ph.getAttribute("farm");
+ String sv = ph.getAttribute("server");
+ String id = ph.getAttribute("id");
+ String sc = ph.getAttribute("secret");
+ String imgURL = "
http://farm"+fm+".
static.flickr.com/"+
+ sv + "/" + id + "_" + sc + "_s.jpg";
+ PImage img = loadImage(imgURL);
+ int x = (i%8) * img.width;
+ int y = (i/8) * img.height;
+ image(img,x,y);
+ }
+}
Modified: trunk/MailMan/Examples/Processing/FlickrBrowser/FlickrBrowser.pde
==============================================================================
--- trunk/MailMan/Examples/Processing/FlickrBrowser/FlickrBrowser.pde
(original)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/FlickrBrowser.pde Sat
Dec 6 10:22:06 2008
@@ -1,237 +1,282 @@
-
-import netP5.*;
-import oscP5.*;
-import java.net.*;
-
-
-OscP5 osc;
-NetAddress myRemoteLocation;
-
-OscProperties oscp;
-OscP5 oscClient;
-OscP5 oscServer;
-
-
-int lastInteraction = millis();
-boolean retry = false;
-
-int MAX_WORDS = 100;
-Vector words;
-
-void setup ()
-{
-
- frameRate(1);
-
- oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
- oscServer = new OscP5(this, 12001, OscP5.UDP);
-
- myRemoteLocation = new NetAddress("127.0.0.1", 12000);
-
- words = new Vector();
-}
-
-
-void draw()
-{
- if (retry) {
- if (millis() > lastInteraction+10000) {
- String c = (String)words.get(words.size()-1);
- //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
- lastInteraction=millis();
- if (ping()) {
- link(URLEncode("
http://www.flickr.com/search/show/?q=\""+c+"\""));
- retry = false;
- } else {
- showNetError();
- }
-
- }
- }
- if (millis() > lastInteraction+1000*60*30) {
- if (words.size() > 0) {
- String c = (String)words.get((int)random(words.size()));
- println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
-
- if (ping()) {
- lastInteraction=millis();
- link(URLEncode("
http://www.flickr.com/search/show/?q=\""+c+"\""));
- } else {
- showNetError();
- lastInteraction=lastInteraction+10*1000; // retry 10 sec later
- }
- }
- }
-}
-
-
-void oscEvent(OscMessage theOscMessage)
-{
-
- if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
- {
- recievePath(theOscMessage);
- }
- else {
- println(theOscMessage);
- }
-
-}
-
-void recievePath(OscMessage theOscMessage)
-{
- retry = false;
- String uuid = (String) theOscMessage.arguments()[0];
- String fname = (String) theOscMessage.arguments()[1];
- String originalFilename = (String) theOscMessage.arguments()[2];
- String filename = (String) theOscMessage.arguments()[4];
- String mimetype = (String) theOscMessage.arguments()[3];
-
- // println(uuid + " " + fname + " " +filename + " "+ mimetype);
-
- int[] n = new int[2];
-
- //String content = s;
-
- String ext = filename;
- ext = ext.substring(ext.lastIndexOf('.') +1);
-
- String content = "";
- if(ext.compareToIgnoreCase("txt") == 0) {
-
- content = parseTxt(filename);
-
- }
- else if(ext.compareToIgnoreCase("vnt") == 0) {
-
- content = parseVnt(filename);
- }
- else { //not supported
- lastInteraction=millis();
- words.add(fname);
- if (words.size() > MAX_WORDS) {
- words.remove(0);
- }
- println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
-
-
- showNotSupported();
- retry = true; // show error, then retry last word
- return;
- }
-
- if (content.length() > 0) {
- lastInteraction=millis();
- words.add(content);
- if (words.size() > MAX_WORDS) {
- words.remove(0);
- }
- println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
- if (ping()) {
-
link(URLEncode("
http://www.flickr.com/search/show/?q=\""+content+"\""));
- } else {
- showNetError();
- retry = true;
- }
-
- }
-}
-
-void showNotSupported() {
- link(sketchPath("notSupported.html"));
-
-}
-void showNetError() {
- link(sketchPath("neterror.html"));
-}
-
-String parseTxt(String filename)
-{
- byte bytes[] = loadBytes(filename);
- //println(bytes);
- String content;
- try{
- if(bytes[0] == -1 && bytes[1] == -2)
- {
- content = new String(bytes, 0, bytes.length , "UTF-16");
- }
- else{
- content = new String(bytes, 0, bytes.length , "ISO-8859-1");
- }
- //tb.addContent(content);
- return content;
-
- }
- catch (UnsupportedEncodingException ex) {
-
- }
- return "";
-
-}
-
-String parseVnt(String filename)
-{
- byte bytes[] = loadBytes(filename);
- //println(bytes);
- String content="";
- String body = "";
- try{
- if(bytes[0] == -1 && bytes[1] == -2)
- {
- content = new String(bytes, 0, bytes.length , "UTF-16");
- }
- else{
- content = new String(bytes, 0, bytes.length , "ISO-8859-1");
- }
- //tb.addContent(content);
-
-
- }
- catch (UnsupportedEncodingException ex) {
- println(ex.getMessage());
- }
-
-
- int start = content.toUpperCase().indexOf("BODY");
- if(start < 0)
- return "";
- content = content.substring(start);
- int dd = content.toUpperCase().indexOf(":");
- if(dd < 0)
- return "";
- content = content.substring(dd+1);
- int nl = content.toUpperCase().indexOf("\n");
- if(nl < 0)
- return "";
- content = content.substring(0, nl);
-
- while(content.toUpperCase().indexOf("=0A") != -1)
- {
- body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
- content = content.substring(content.toUpperCase().indexOf("=0A")+3);
- }
- body += content;
-
-
- return body;
-
-}
-
-void mousePressed() {
- println(ping());
-
-}
-
-boolean ping() {
-
- try {
- Socket s = new Socket("
jorgecardoso.eu", 80);
- } catch(Exception e) {
- return false;
- }
- return true;
-
-}
-
-
+
+import netP5.*;
+import oscP5.*;
+import java.net.*;
+
+
+OscP5 osc;
+NetAddress myRemoteLocation;
+
+OscProperties oscp;
+OscP5 oscClient;
+OscP5 oscServer;
+
+
+int lastInteraction = millis();
+boolean retry = true;
+
+int MAX_WORDS = 100;
+Vector words;
+
+void setup ()
+{
+ size(400, 400);
+ frameRate(1);
+ xml = new XMLInOut(this);
+ oscClient = new OscP5(this, "127.0.0.1", 12000, OscP5.UDP);
+ oscServer = new OscP5(this, 12001, OscP5.UDP);
+
+ myRemoteLocation = new NetAddress("127.0.0.1", 12000);
+
+ words = new Vector();
+
+ loadWords();
+
+ // println(search("jorge"));
+}
+
+void loadWords() {
+ String [] wordsFile = loadStrings(sketchPath("words.txt"));
+ for (int i = 0; i < wordsFile.length; i++) {
+ words.add(wordsFile[i]);
+ }
+}
+
+void saveWords() {
+ String []wordsFile = new String[words.size()];
+ for (int i = 0; i < wordsFile.length; i++) {
+ wordsFile[i] = (String)words.get(i);
+ }
+ saveStrings(sketchPath("words.txt"), wordsFile);
+}
+
+void draw()
+{
+ if (retry) {
+ if (millis() > lastInteraction+10000) {
+ String c = (String)words.get(words.size()-1);
+ //println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Using friendly name "+c);
+ lastInteraction=millis();
+ if (ping()) {
+ if (search(c)) {
+ //println(c);
+
link(URLEncode("
http://www.flickr.com/search/show/?q=\""+c+"\""));
+
+ retry = false;
+ } else {
+ showNumError();
+ retry = false;
+ lastInteraction = -1000*60*30;
+ }
+ }
+ else {
+ //lastInteraction =
+ showNetError();
+ }
+
+ }
+ }
+ if (millis() > lastInteraction+1000*60*30) {
+ if (words.size() > 0) {
+ String c = (String)words.get((int)random(words.size()));
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " ---- Reusing old tag "+c);
+
+ if (ping()) {
+ if (search(c)) {
+ lastInteraction=millis();
+
link(URLEncode("
http://www.flickr.com/search/show/?q=\""+c+"\""));
+ }
+ }
+ else {
+ showNetError();
+ lastInteraction=lastInteraction+10*1000; // retry 10 sec later
+ }
+ }
+ }
+}
+
+
+void oscEvent(OscMessage theOscMessage)
+{
+
+ if(theOscMessage.addrPattern().equals("/Diablu/Mailman/ReceivePath"))
+ {
+ recievePath(theOscMessage);
+ }
+ else {
+ println(theOscMessage);
+ }
+
+}
+
+void recievePath(OscMessage theOscMessage)
+{
+ retry = false;
+ String uuid = (String) theOscMessage.arguments()[0];
+ String fname = (String) theOscMessage.arguments()[1];
+ String originalFilename = (String) theOscMessage.arguments()[2];
+ String filename = (String) theOscMessage.arguments()[4];
+ String mimetype = (String) theOscMessage.arguments()[3];
+
+ // println(uuid + " " + fname + " " +filename + " "+ mimetype);
+
+ int[] n = new int[2];
+
+ //String content = s;
+
+ String ext = filename;
+ ext = ext.substring(ext.lastIndexOf('.') +1);
+
+ String content = "";
+ if(ext.compareToIgnoreCase("txt") == 0) {
+
+ content = parseTxt(filename);
+
+ }
+ else if(ext.compareToIgnoreCase("vnt") == 0) {
+
+ content = parseVnt(filename);
+ }
+ else { //not supported
+ lastInteraction=millis();
+ words.add(fname);
+
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ saveWords();
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " fname " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + fname);
+
+
+ showNotSupported();
+ retry = true; // show error, then retry last word
+ return;
+ }
+
+ if (content.length() > 0) {
+ lastInteraction=millis();
+ words.add(content);
+ if (words.size() > MAX_WORDS) {
+ words.remove(0);
+ }
+ saveWords();
+ println(year() + "-" + month() + "-" + day() + "@" + hour() + ":"
+minute()+":" +second() + " content " + uuid + " "+ fname + " " +
originalFilename + " " + filename + " " + mimetype + " " + content);
+ if (ping()) {
+ if (search(content)) {
+
link(URLEncode("
http://www.flickr.com/search/show/?q=\""+content+"\""));
+ }
+ else {
+ showNumError();
+ lastInteraction = millis()-1000*60*30;
+ //retry = true;
+ }
+ }
+ else {
+ showNetError();
+ retry = true;
+ }
+
+ }
+}
+
+void showNotSupported() {
+ link(sketchPath("notSupported.html"));
+
+}
+void showNetError() {
+ link(sketchPath("neterror.html"));
+}
+void showNumError() {
+ link(sketchPath("numerror.html"));
+}
+String parseTxt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content;
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+ return content;
+
+ }
+ catch (UnsupportedEncodingException ex) {
+
+ }
+ return "";
+
+}
+
+String parseVnt(String filename)
+{
+ byte bytes[] = loadBytes(filename);
+ //println(bytes);
+ String content="";
+ String body = "";
+ try{
+ if(bytes[0] == -1 && bytes[1] == -2)
+ {
+ content = new String(bytes, 0, bytes.length , "UTF-16");
+ }
+ else{
+ content = new String(bytes, 0, bytes.length , "ISO-8859-1");
+ }
+ //tb.addContent(content);
+
+
+ }
+ catch (UnsupportedEncodingException ex) {
+ println(ex.getMessage());
+ }
+
+
+ int start = content.toUpperCase().indexOf("BODY");
+ if(start < 0)
+ return "";
+ content = content.substring(start);
+ int dd = content.toUpperCase().indexOf(":");
+ if(dd < 0)
+ return "";
+ content = content.substring(dd+1);
+ int nl = content.toUpperCase().indexOf("\n");
+ if(nl < 0)
+ return "";
+ content = content.substring(0, nl);
+
+ while(content.toUpperCase().indexOf("=0A") != -1)
+ {
+ body += content.substring(0, content.toUpperCase().indexOf("=0A"))
+ " ";
+ content = content.substring(content.toUpperCase().indexOf("=0A")+3);
+ }
+ body += content;
+
+
+ return body;
+
+}
+
+void mousePressed() {
+ println(ping());
+
+}
+
+boolean ping() {
+
+ try {
+ Socket s = new Socket("
jorgecardoso.eu", 80);
+ }
+ catch(Exception e) {
+ return false;
+ }
+ return true;
+
+}
+
+
Added: trunk/MailMan/Examples/Processing/FlickrBrowser/numerror.html
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/numerror.html Sat Dec
6 10:22:06 2008
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"
http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title>Untitled Document</title>
+<style type="text/css">
+<!--
+body {
+ background-color: #000000;
+}
+body,td,th {
+ font-family: Arial, Helvetica, sans-serif, Arial Black;
+ color: #FFFFFF;
+}
+.centro {
+ border: 1px solid #FFFFFF;
+}
+.style1 {font-size: medium}
+.style2 {font-size: x-large; }
+-->
+</style>
+<script language="JavaScript" type="text/JavaScript">
+<!--
+function MM_reloadPage(init) { //reloads the window if Nav4 resized
+ if (init==true) with (navigator) {if
((appName=="Netscape")&&(parseInt(appVersion)==4)) {
+ document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
+ else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
location.reload();
+}
+MM_reloadPage(true);
+//-->
+</script>
+</head>
+
+<body>
+<div id="Layer1" style="position:absolute; left:415px; top:303px;
width:350px; height:151px; z-index:1" class="centro">
+ <p class="style2">Oops! </p>
+ <p class="style1">Parece essa palavra n�o d� resultados...</p>
+ <p class="style1">Queres tentar outra vez? </p>
+</div>
+</body>
+</html>
Modified: trunk/MailMan/Examples/Processing/FlickrBrowser/start.bat
==============================================================================
--- trunk/MailMan/Examples/Processing/FlickrBrowser/start.bat (original)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/start.bat Sat Dec 6
10:22:06 2008
@@ -1 +1,2 @@
-java -cp
application.windows\lib\core.jar;application.windows\lib\FlickrBrowser.jar;application.windows\lib\oscP5.jar
processing.core.PApplet FlickrBrowser >> flickrBrowser.log
+java -cp
application.windows\lib\core.jar;application.windows\lib\proxml.jar;application.windows\lib\FlickrBrowser.jar;application.windows\lib\oscP5.jar
processing.core.PApplet FlickrBrowser >> flickrBrowser.log
+#java -cp
application.windows\lib\core.jar;application.windows\lib\FlickrBrowser.jar;application.windows\lib\oscP5.jar
processing.core.PApplet FlickrBrowser >> flickrBrowser.log
Added: trunk/MailMan/Examples/Processing/FlickrBrowser/words.txt
==============================================================================
--- (empty file)
+++ trunk/MailMan/Examples/Processing/FlickrBrowser/words.txt Sat Dec 6
10:22:06 2008
@@ -0,0 +1,9 @@
+diablu
+art
+sheep
+bgustavocosta
+molheiascalcas
+madeira
+Fail
+terror
+Jorge