Psychic Fortune Teller - en automat som läser hos Twitter (26 / 32 steg)
Fullständig skiss med vissa tolkning
Version 9. Detta är den psykiska hjärna Processing skissen vid tiden för utgivningen av detta Instructable.
Alla ändringar kommer att vara på Git repo
https: cb2.setOAuthAccessToken(twitOAuthAccessToken); github.com/rosemarybeetle/psychic-fortune-teller
krediter
cb2.setOAuthAccessTokenSecret(twitOAuthAccessTokenSecret);
Twitter twitter2 = new TwitterFactory(cb2.build()).getInstance();
try {
Status status = twitter2.updateStatus(fortune);
println("Successfully tweeted the message: "+fortune + " to user: [ + status.getText() + "]."); // DEBUG STUFF
delayCheck=millis();
}
catch(TwitterException e) {
println("Send tweet: " + e + " Status code: " + e.getStatusCode());
} // end try
;
}
}
else {
tts.speak("You have not entered your Twitter user nayme. Sorry. I cannot reed your fortune. without this") ; // THE BOX WAS EMPTY
}
}
.// <<<<<<<<<<<<<<<<<<<<<<<<< END SEND TWEETS <<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>> GRAB THOSE TWEETS >>>>>>>>>>>>>
void grabTweets() {
color cl3 = color(70, 130, 180); This sketch is the mind control of Psychic Fortune Teller, an automaton that can read the collective mind of twitter
fill (cl3); It has a Processing brain connected to a Twitter app, connecting via OAUTH
rect(0, (height/2)-120, width, 90); It harvests tweets from predefined searchs
fill(0, 25, 89, 255); Deconstructs the weet content into words, hashtags, usernames and urls
textSize(70); Then uses these to create fortune readings, which it speaks using text-to-speeach
text("Reading the collective mind...", (width/8)-120, (height/2)-50); // THE ALERT FOR UPDATE CHECKING PAUSE it also tweets a summary.
loadRemoteAdminSettings(); // GET THE LATEST ADMIN FROM GOOGLE SPREADSHEET
//Credentials RESPECT to...
ConfigurationBuilder cbTest = new ConfigurationBuilder();
// ------- NB - the variables twitOAuthConsumerKey, etc. ARE IN A SEPARATE SHEET JER THORP - Visualisation is based on his code example
cbTest.setOAuthConsumerKey(twitOAuthConsumerKey); see http:cbTest.setOAuthConsumerSecret(twitOAuthConsumerSecret);blog.blprnt.com/blog/blprnt/updated-quick-tutorial-processing-twitter
cbTest.setOAuthAccessToken(twitOAuthAccessToken); Awesome!
cbTest.setOAuthAccessTokenSecret(twitOAuthAccessTokenSecret);
Twitter twitterTest = new TwitterFactory(cbTest.build()).getInstance(); The people behind twitter4j
try { // TRY ALLOWS ERROR HANDLING FOR EXCEPTIONS... see https:Query query = new Query(queryString); // this is default you check the first of 4 admin settings, but should be extended to include passing a selctor paramgithub.com/yusuke/twitter4j/network
query.count(int(adminSettings[3])); // count is the number of tweets returned per page using here, version 3.03
QueryResult result = twitterTest.search(query); // gets the query NOTE - you have to have the twitter4j library installed in the libraries folder for this to work!
int ll=1; // DEBUG STUFF You need to register your app to get OAUTH keys for Twitter4j
for (Status status : result.getTweets()) { // EXTRACT THE TWEETS You can put them in a separate tab in your sketch
String user = status.getUser().getScreenName();// GET THE TWITTER USERNAME
usernames.add(user); // ADD TO THE ARRAYLIST FOR USERNAMES Andreas Schlegel - controlP5 GUI Library
String msg = status.getText(); // EXTRACT THE TWEET TEXT see http:println ("tweet #"+ll); // DEBUG STUFFwww.sojamo.de/libraries/controlP5/
println(" + user); // DEBUG STUFF For positioning see (also Andreas Schlegel -
println("Text of tweet=" + status.getText()); // DEBUG STUFF https:println ("-----------");code.google.com/p/controlp5/source/browse/trunk/examples/controlP5button/controlP5button.pde?r=6
ll++; // DEBUG STUFF (INCREMENT)
//Break the tweet into words Nikolaus Gradwohl for the GURU text to speech library for Processing
String[] input = msg.split(" "); // BREAK DOWN THE TWEET USING SPACES AS A DELIMITER see http:for (int j = 0; j < input.length; j++) {www.local-guru.net/blog/pages/ttslib
cleanTweets.add(input[j]); // CLEANTWEETS IS A STORE FOR TWEET WORDS WITH STOP WORDS REMOVED
for (int ii = 0 ; ii < stopWords.size(); ii++) {-
initiering
if (stopWords.get(ii).equals(input[j])) { >cleanTweets.remove(input[j]); // THIS WORD IS A STOP WORD - REMOVE IT!>println("Word removed due to matched stopword: "+input[j]); // DEBUG STUFF>} // end if>} //end for (ii++) //stopword c>}// end clean this msg>}// end of all tweet cleaning
println ("cleanTweets = "+cleanTweets);
for (int k = 0; k < cleanTweets.size(); k++) {
if ((cleanTweets.get(k).equals(queryString))!= true)
{
println ("(cleanTweets.get(k) <"+cleanTweets.get(k)+".equals(queryString))"+queryString+"!= true"); <words.add(cleanTweets.get(k));<if (words.size() >int(adminSettings[6]))<{<words.remove(0);<} // keeps aray to a finite length by dropping off first element as new one is added<// >>>>>> make the list of hashtags end load flags
String hashtag= cleanTweets.get(k); >String hashtagArray[] = hashtag.split("#");>if (hashtagArray.length>1)>{>//println ("inside checker");>hashtags.add(hashtagArray[1]); fortune variables initialisations
int v=words.size()-1;
words.remove(v);
if (queryType.equals("hashtag"))
{
if (hashtagArray[1].equals("#"+queryString)) {
hashtags.remove(hashtagArray[1]);
} <else if (hashtags.size() >int(adminSettings[6])/10)<{<hashtags.remove(0);<} // keeps aray to a finite length by dropping off first element as new one is added<}<println ("hashtagArray["+k+"]= "+hashtagArray[1]);
} >// <<<<<<<>// >>>>>>> set up list of usernames>String username= cleanTweets.get(k);>String usernameArray[] = username.split(">// println ("usernameArray = ");>//println (usernameArray); gui variables init...
String tfUserCurrent =""if (usernameArray.length>1) { used to check what is in the username text box
String tfTextCurrent =""int vv=words.size()-1; // takes out the username by removing last entry in words() words.remove(vv);// used to check what is in the free-text text box
int valFocus = 0// println ("usernameArray["+j+"]= "+usernameArray[1]); } default
if (usernames.size() >int(adminSettings[6])/6)
{
usernames.remove(0);
} // keeps aray to a finite length by dropping off first element as new one is added
// <<<<<<<<
// >>>>>>>> set up urls >>>>>> <String url = cleanTweets.get(k);<String urlArray[] = url.split("h");<if (urlArray.length>1)<{<String urlArray2[] = urlArray[1].split("t");<if (urlArray2.length>2)
{ >urls.add(url);>int vvv=words.size()-1;>words.remove(vvv);>}>else if (urls.size() >int(adminSettings[6])/6)>{ urls.remove(0);s to hold all of the words that we get from the imported tweets
} // keeps aray to a finite length by dropping off first element as new one is added
stopWords = new // <<<<<<<<<< end()// >>>>>>>>>>
}
cleanTweets = new };()}
println ("WORDS.SIZE () = "+words.size());
words = new println ("words = "+words);()println ("
// >>>>>>> create text log file of words from pyschic scanning >>>>>>>>>
hashtags = new for (int p =0;p()
{
uberWords = append (uberWords, words.get(p).toString());
usernames = new }()uberWords = append (uberWords, "WORDS UPDATE REFRESH COMPLETED");
uberWords = append (uberWords, " ");
urls = new saveStrings ("words-"+stamp+".txt", uberWords);()// <<<<<< end word text log file
// >>>>>> create log file of users tweetster = new for (int jj =0;jj()
{
String uberWords [] = new String[0]uberUsers = append (uberUsers, " }massive array to build up history of words harvested
String uberHashtags [] = new String[0]saveStrings ("users-"+stamp+".txt", uberUsers); // <<<<<<<<< end user text log filemassive array to build up history of hashtags harvested
String uberUsers [] = new String[0]// >>>>>> create log file of hashtags for (int jj =0;jjmassive array to build up history of users harvested
String uberUrls [] = new String[0]
{ uberHashtags = append (uberHashtags, "#"+hashtags.get(jj).toString());massive array to build up history of urls harvested
String queryString = ""} saveStrings ("hashtags-"+stamp+".txt", uberHashtags);
String queryType = ""// <<<<<<<<< end hashtag text log file // >>>>>> create log file of urls
for (int jj =0;jj
fortFrags1 = new
{()uberUrls = append (uberUrls, urls.get(jj).toString());
}
fortFrags2 = new saveStrings ("urls-"+stamp+".txt", uberUrls);()// <<<<<<<<< end url text log file
} //end try ??
fortFrags3 = new catch(TwitterException e) {()println("TEST query tweet: " + e + " Status code: " + e.getStatusCode());
} // end try/catch
fortFrags4 = new grabTime=millis(); // reset grabTime()if (loadSettingsFirstLoadFlag==true)
{ <loadSettingsFirstLoadFlag =false; //<//this is the line that will cause subsequqnt updates to remove the first word(0)<}<cleanTweets.clear();<tweetster.clear();<} // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end grabTweets() <<<<<<<< Variables for admin and tweettexts - e.g Array for containing imported admin settings from Google spreadsheet (init with default settings)
void buttonCheck(String tweetTextIntro)
{
if (b.isPressed()) {println("button being pressed");
sendTweet ("digital (onscreen) Button MOUSE");
b.setWidth(50);
// action for onscreen button press
}
}
// <<<<<<<<<<<<<<<<<<<<<<< end of BUTTONCHECK
// >>>>>>>>>>>>>>> check the open serial port >>>>>>>>>>
void checkSerial() {
println (); >//println ("inside checkSerial()");>try {>// >>>>>> see if the port is sending you stuff>while (port.available () > 0) {>String inByte = port.readString();>println ("Safe from OUSIDE IF . inByte = "+inByte); grabTweets Timer settings >int w=int(random(150));>b.setWidth(w);>println ();>port.clear();>sendTweet ("physical Button");>}>} // end try>catch (Exception e) {>println ("Check serial exception = "+e);>}>} // <<<<<<<<<<<<<<<<<<<<< end checkSerial <<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>> load remote admin settings >>>>>>>>>>>>>>
void loadRemoteAdminSettings ()
String stamp = year()+"-"+month()+"-"+day()+"-"+hour()+"-"+minute(){try { <String checkRandomSpeech = adminSettings[8];<adminSettings = loadStrings("https://docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdFNOcGtMaXZnS3IwdTJacllUT1hLQUE&output=txt");<if ((checkRandomSpeech.equals(adminSettings[8]))!=true) {<tts.speak(adminSettings[8]);<}<for (int i = 0 ; i < adminSettings.length; i++) {
Ställ in GUI gränssnitt-byggnaden library (ControlP5)
println("adminSettings["+i+"]= "+adminSettings[i]); >} // end for>if (adminSettings[5].equals("h")) {>println ("use hashtag for search");>queryString = adminSettings[0];>queryType = "hashtag";>} GUI library and settings
import controlP5.*if (adminSettings[5].equals("u")) { import the GUI library
ControlP5 cp5println ("use username phrase for search"); queryString = adminSettings[1]; creates a controller (I think!)
queryType = "username";
}
if (adminSettings[5].equals("s"))
{
println ("use search term for search"); <queryString = adminSettings[2];<queryType = "search term";<}<updateDisplayVariables();<// now load load fortune fragments<String frag1 []= loadStrings ("https://docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdDQ3cUZ5Y2RMTm9RSXNrdElZTjN5R1E&output=txt");<for (int ff1=0; ff1
Ställa in text till tal-bibliotek (GURU)
{ >fortFrags1.add(frag1[ff1]);>println ("Fortune Frag1 = "+fortFrags1.get(ff1));>}>String frag2 []= loadStrings ("https://docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdGFQLTFhMUVqTTlkTjlRVUN4c3JtOGc&output=txt");>for (int ff2=0; ff2>
{>fortFrags2.add(frag2[ff2]); import GURU text-to-speech library
import guru.ttslib.*println ("Fortune Frag2 = "+frag2[ff2]); println ("Fortune Frag1 = "+fortFrags2.get(ff2)); NB this also needs to be loaded (available from http:}www.local-guru.net/projects/lib/ttslib-0.3.zip)
TTS ttsString frag3 []= loadStrings ("https://docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdFE0Qm1yYmhyYWJETVJsSHJIOGFMQ3c&output=txt"); for (int ff3=0; ff3 create an instance called 'tts'
{ <fortFrags3.add(frag3[ff3]);<println ("Fortune Frag3 = "+frag3[ff3]);<}<String frag4 []= loadStrings ("https://docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdG9KTnhLS2Zvbk5HNXp2RmRpeUZtTUE&output=txt");<for (int ff4=0; ff4<
{<fortFrags4.add(frag4[ff4]);
println ("Fortune Frag4 = "+frag4[ff4]); >}>// end if>}>catch (Exception e) {>println ("no CONNECTION");>}>} import standard processing Serial library
// >>>>
Serial port
void loadRemoteStopWords () { create an instance called 'port'
try { <String stopWordsLoader [] = loadStrings("https://docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdFByYk41am9jRnRkeU9LWnhjZFJTOEE&output=txt");<if (loadstopWordsCheckInt==true)<{<for (int i = 0 ; i < stopWordsLoader.length; i++) {<//stop<stopWords.add(stopWordsLoader[i]);<println("stopWords["+i+"]= "+stopWords.get(i)+". Length now: "+stopWords.size());
} >loadstopWordsCheckInt=false;>}>}>catch (Exception e)>{>println("jjjjjjjjjjjjj"); needed to stop Twitter overpolling from within sendTweet
float tweetTimer = 5000} } wait period (in milliseconds) after sending a tweet, before you can send the next one
float timerT=millis()void keyReleased() { if (key==TAB) { temporary timer for sendTweet
float delayCheckprintln ("Tab key released"); //tfToggleFocus(valFocus);delayCheck} else if ((key==ENTER )|(key == RETURN)) { THIS IS IMPORTANT. it i what stops overpollin g of the Twitter API
sendTweet("pressed return"); <}<}<void tfToggleFocus (int val)<{</*if (val==0)<{ End of main initialisation
Main SETUP() funktion...
tf.setFocus(true);
tts = new TTS()tf.setColorBackground(focusBackgroundColor); tf.setColor(focusColor); create text to speech instance
tts.speak(adminSettings[8])valFocus=1;} preloaded, not web
else if (val==1) { adminSettings 1 " + adminSettings)tf.setFocus(false); tf.setColorBackground(focusOffBackgroundColor); DEBUG STUFF
tf.setColor(focusOffColor);
println("adminSettings["+i+"]= "+adminSettings[i])valFocus=0; }*/ DEBUG STUFF
tf.setFocus(true);
tf.setColorBackground(focusBackgroundColor);
tf.setColor(focusColor);
loadRemoteAdminSettings()} void updateDisplayVariables() { loads Twitter search parameters from remote Google spreadsheet
// Reading the mind queryString
tts.speak("I am connected to the web. Master.Your commands have been loaded into my brain")String currentHashtag = adminSettings [0]; String displayHashtag = "hashtag = "+adminSettings [0]+" "; DEBUG STUFF - SPOKEN OUT. ONLY WORKS IF CONNECTION WORKS
if (adminSettings[0]=="")
{
tts.speak("I am sorry. I am not able to connect to the web. Your commands have not been loaded into my brain master")displayHashtag=""; } DEBUG STUFF
String currentUserName = adminSettings [1];
loadRemoteStopWords()String displayUserName = " = "+adminSettings [1]+" ";if (adminSettings[1]=="") load list of stop words into an array, loaded from a remote spreadsheet
{ >displayUserName="";>}>String currentSearchTerms = adminSettings [2];>String displaySearchTerms = "search = "+adminSettings [2];>if (adminSettings[2]=="")>{>displayUserName=""; screen size and settings....
size(screen.width-border, screen.height-border)}readingSettingText = "Reading the hive mind for "+queryType+"= "+ queryString; USE THIS SETTING FOR EXPORTED APPLICATION IN FULLSCREEN (PRESENT) MODE
background(0)color cl = color(70, 30, 180);// not in use color cl2 = color(70, 230, 180);//not in use SET BACKGROUND TO BLACK
fill (clPanel); <//rect(30, boxY+15, width, 105);<fill(0, 0, 0, 255);<textSize(40);<//text(readingSettingText, 10, boxY+40);<//rect(0, boxY+13, width, 1);<textSize(40);<text(" 2, boxY+33);
fill (clPanel); >rect(columnPos2_X, boxY-10, width, 50);>fill(0, 0, 0, 255);>textSize(35);>//text(adminSettings[7], columnPos2_X+30, boxY-25);>text(" Make initial serial port connection handshake
println(Serial.list())
//displayHashtag+displayUserName+displaySearchTerms;}
void buildAdminPanel() { DEBUG STUFF - display communication ports (use this in test for available ports)
int panelTop = height-panelHeight;
port = new Serial(this, Serial.list()[0], 115200)fill (clPanel); rect(0, panelTop, width, panelHeight); OPEN PORT TO ARDUINO
// >>>>>>> set up fonts
//PFont font = createFont("arial",20);
font = new ControlFont(createFont("arial", 100), 40); if errors
// <<<<<<<// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> set up GUI elements >>>>>>>>>>>>>>>>>>>>---")noStroke();
cp5 = new ControlP5(this); // adds in a control instance to add buttons and text field to
noStroke();Exception = "+ae)tf = cp5.addTextfield(""); tf.setPosition(border, boxY); print it
tf.setSize(boxWidth, boxHeight);tf.setColorBackground(focusBackgroundColor);---")tf.setColor(focusColor);
tf.setFont(font);tf.setFocus(true);---")//tf.setAutoClear(true);
tf.captionLabel().setControlFont(font);
// <// create a new button with name 'Tell my Fortune'<b = cp5.addButton("but", 20, 100, 50, 80, 20);<b.setId(2); // id to target this element<b.setWidth(250); // width<b.setHeight(25);<b.setPosition(border, boxY+100);<b.captionLabel().setControlFont(font);
b.captionLabel().style().marginLeft = 1;
b.captionLabel().style().marginTop = 1;
b.setVisible(true); b.isOn(); Now call tweeting action functions...
b.setColorBackground(focusOffBackgroundColor);
//
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end of GUI <<<<<<<<<<
// >>>>>>>> } <
void readFortune (String tweetText)<{<int picW1 = int(random (words.size()));<String fortuneWord1= words.get(picW1);<int picW2 = int(random (words.size()));<String fortuneWord2= words.get(picW2);<int hash = int(random (hashtags.size()));<String fortuneHash= hashtags.get(hash);<int urler = int(random (urls.size()));<String fortuneUrl= urls.get(urler);<int userer = int(random (usernames.size()));<String fortuneUser = usernames.get(userer);<int frag1Int =int (random (fortFrags1.size()));<String fraglet1 = fortFrags1.get(frag1Int);<int frag2Int =int (random (fortFrags2.size()));<String fraglet2 = fortFrags2.get(frag2Int);<int frag3Int =int (random (fortFrags3.size()));<String fraglet3 = fortFrags3.get(frag3Int);<int frag4Int =int (random (fortFrags4.size()));<String fraglet4 = fortFrags4.get(frag4Int);<fortune = "Psychic summary for + ". for: #"+queryString+". "+ fortuneWord1+", "+ fortuneWord2+", #"+fortuneHash+ ", "+fortuneUrl+". Enjoy/RT";<println ("just before fortune spoken");<fortuneSpoken = "Hello. "+tfUserCurrent+". "+adminSettings[7]+ ". "+fortuneGreeting +". Here. you are. Your Psychic Hive Mind. Fortune. based on reading .the collective mind of. "+queryString+". is. "+fraglet1+". "+ fortuneWord1+". "+ fraglet2+". "+fortuneWord2+". "+fraglet3+". hashtag."+fortuneHash+ ". "+fraglet4+". Twitter user."+fortuneUser+". Thank you. I have tweeted a psychic summary of this reading to your twitter account. Moove along now. " ;<println ("fortuneSpoken= "+fortuneSpoken);<}<http://search.twitter.com/search.json?q=%23museumnext<<<<<<<<<<<<<<<<< end of setup() <<<<<<<<<<<<<<<<<<<<<<<<<<
Main LOOP() funktion
buttonCheck("HELLO") on screen check button every loop
>>>>>> Draw a faint black rectangle over what is currently on the stage so it fades over time.
fill(0, 30) change the latter number to make the fade deeper (from 1 to 20 is good)
<<<<<<
>>>>>>> WORDS
Draw a word from the list of words that we've built
<<<<<<<
>>>>>>> HASHTAGS
Draw a hashtag from the list of words that we've built
<<<<<<<
>>>>>> USERNAMES
Draw a username from the list of words that we've built
<<<<<<
>>>>>> URLS
Draw a url from the list of words that we've built
<<<<<<
-------------
>>>>> Put url somewhere random on the stage, with a random size and colour
text(url, random(width)-widthRandomiser, random(panelTop))
<<< SEND URL TO THE SCREEN
>>> SENDs HASHTAG TO THE SCREEN WITH DIFFERENT SIZE
<<< END SEND HASHTAG#
>>>SEND WORD TO SCREEN ALSO WITH DIFFERENT SETTINGS
<<< END SEND WORD
>>> SEND USERNAME TO SCREEN
<<< END SEND USERNAME
----------
following is for text boxes background.
tfUserCurrent=tf.getText() check the text box content every loop
tfUserCurrent= "+tfUserCurrent) DEBUG STUFF
checkSerial() check serial port every loop
Funktionen SENDTWEET() - skickar tweets!
>>>>>>>>>>>>>>>>>>>>>>>> SEND THAT TWEET >>>>>>>>>>>>>>>
void sendTweet (String tweetText)
if ((tfUserCurrent.equals(""))!=true) THE BOX CAN'T BE EMPTY
timerT=millis() reset the timer each time
this is needed to prevent sending multiple times rapidly to Twitter
which will be frowned upon!
RESET A TIMER
println("tweet being sent") DEBUG STUFF
println("tfUserCurrent = "+ tfUserCurrent) DEBUG STUFF
tweetTextIntro = readingSettingText INITIALISE THE INTRO TEXT VARIABLE...
println("tweet Send actions complete over") DEBUG STUFF
--- NB - the variables twitOAuthConsumerKey, are in a seperate tab
println("Successfully tweeted the message: "+fortune + " to user: [ + status.getText() + "].") DEBUG STUFF
catch(TwitterException e)
end try
else
tts.speak("You have not entered your Twitter user nayme. Sorry. I cannot reed your fortune. without this") THE BOX WAS EMPTY
<<<<<<<<<<<<<<<<<<<<<<<<< END SEND TWEETS <<<<<<<<<<<<<<<
Funktionen GRABTWEETS() - Detta är den huvudsakliga skörda funktionen
>>>>>>>>>>>>>>>>>>>>>>>>> GRAB THOSE TWEETS >>>>>>>>>>>>>
void grabTweets()
color cl3 = color(70, 130, 180)
fill (cl3)
rect(0, (height/2)-120, width, 90)
fill(0, 25, 89, 255)
textSize(70)
Reading the collective mind...", (width/8)-120, (height/2)-50) THE ALERT FOR UPDATE CHECKING PAUSE
loadRemoteAdminSettings() GET THE LATEST ADMIN FROM GOOGLE SPREADSHEET
Credentials
ConfigurationBuilder cbTest = new ConfigurationBuilder()
--- NB - the variables twitOAuthConsumerKey, etc. ARE IN A SEPARATE SHEET
cbTest.setOAuthConsumerKey(twitOAuthConsumerKey)
cbTest.setOAuthConsumerSecret(twitOAuthConsumerSecret)
cbTest.setOAuthAccessToken(twitOAuthAccessToken)
cbTest.setOAuthAccessTokenSecret(twitOAuthAccessTokenSecret)
Twitter twitterTest = new TwitterFactory(cbTest.build()).getInstance()
TRY ALLOWS ERROR HANDLING FOR EXCEPTIONS...
Query query = new Query(queryString) this is default you check the first of 4 admin settings, but should be extended to include passing a selctor param
query.count(int(adminSettings[3])) count is the number of tweets returned per page
QueryResult result = twitterTest.search(query) gets the query
int ll=1 DEBUG STUFF
for (Status status : result.getTweets()) EXTRACT THE TWEETS
String user = status.getUser().getScreenName() GET THE TWITTER USERNAME
usernames.add(user) ADD TO THE ARRAYLIST FOR USERNAMES
String msg = status.getText() EXTRACT THE TWEET TEXT
tweet #"+ll) DEBUG STUFF
println(" + user) DEBUG STUFF
println("Text of tweet=" + status.getText()) DEBUG STUFF
-----------")
ll++ DEBUG STUFF (INCREMENT)
Break the tweet into words
String[] input = msg.split(" ") BREAK DOWN THE TWEET USING SPACES AS A DELIMITER
for (int j = 0 j < input.length j++)
cleanTweets.add(input[j]) CLEANTWEETS IS A STORE FOR TWEET WORDS WITH STOP WORDS REMOVED
for (int ii = 0 ii < stopWords.size() ii++)
if (stopWords.get(ii).equals(input[j]))
cleanTweets.remove(input[j]) THIS WORD IS A STOP WORD - REMOVE IT!
println("Word removed due to matched stopword: "+input[j]) DEBUG STUFF
end if
end for (ii++) stopword c
end clean this msg
end of all tweet cleaning
cleanTweets = "+cleanTweets)
for (int k = 0 k < cleanTweets.size() k++)
(cleanTweets.get(k) <"+cleanTweets.get(k)+".equals(queryString))"+queryString+"!= true")
words.add(cleanTweets.get(k))
if (words.size() >int(adminSettings[6]))
words.remove(0)
keeps aray to a finite length by dropping off first element as new one is added
>>>>>> make the list of hashtags
String hashtag= cleanTweets.get(k)
String hashtagArray[] = hashtag.split("#")
if (hashtagArray.length>1)
inside checker")
hashtags.add(hashtagArray[1])
int v=words.size()-1
words.remove(v)
if (hashtagArray[1].equals("#"+queryString))
hashtags.remove(hashtagArray[1])
else if (hashtags.size() >int(adminSettings[6])/10)
hashtags.remove(0)
keeps aray to a finite length by dropping off first element as new one is added
hashtagArray["+k+"]= "+hashtagArray[1])
<<<<<<<
>>>>>>> set up list of usernames
String username= cleanTweets.get(k)
usernameArray = ")
println (usernameArray)
if (usernameArray.length>1)
int vv=words.size()-1 takes out the username by removing last entry in words()
words.remove(vv)
usernameArray["+j+"]= "+usernameArray[1])
if (usernames.size() >int(adminSettings[6])/6)
usernames.remove(0)
keeps aray to a finite length by dropping off first element as new one is added
<<<<<<<<
>>>>>>>> set up urls >>>>>>
String url = cleanTweets.get(k)
String urlArray[] = url.split("h")
if (urlArray.length>1)
String urlArray2[] = urlArray[1].split("t")
if (urlArray2.length>2)
urls.add(url)
int vvv=words.size()-1
words.remove(vvv)
else if (urls.size() >int(adminSettings[6])/6)
urls.remove(0)
keeps aray to a finite length by dropping off first element as new one is added
<<<<<<<<<< end
>>>>>>>>>>
WORDS.SIZE () = "+words.size())
words = "+words)
>>>>>>> create text log file of words from pyschic scanning >>>>>>>>>
for (int p =0p
uberWords = append (uberWords, words.get(p).toString())
uberWords = append (uberWords, "WORDS UPDATE REFRESH COMPLETED")
uberWords = append (uberWords, " ")
saveStrings ("words-"+stamp+".txt", uberWords)
<<<<<< end word text log file
>>>>>> create log file of users
for (int jj =0jj
saveStrings ("users-"+stamp+".txt", uberUsers)
<<<<<<<<< end user text log file
>>>>>> create log file of hashtags
for (int jj =0jj
uberHashtags = append (uberHashtags, "#"+hashtags.get(jj).toString())
saveStrings ("hashtags-"+stamp+".txt", uberHashtags)
<<<<<<<<< end hashtag text log file
>>>>>> create log file of urls
for (int jj =0jj
uberUrls = append (uberUrls, urls.get(jj).toString())
saveStrings ("urls-"+stamp+".txt", uberUrls)
<<<<<<<<< end url text log file
end try ??
catch(TwitterException e)
println("TEST query tweet: " + e + " Status code: " + e.getStatusCode())
end try/catch
grabTime=millis() reset grabTime
loadSettingsFirstLoadFlag =false
this is the line that will cause subsequqnt updates to remove the first word(0)
cleanTweets.clear()
tweetster.clear()
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end grabTweets() <<<<<<<<
Funktionen BUTTONCHECK() - kontroll för interaktion
if (b.isPressed())
println("button being pressed")
sendTweet ("digital (onscreen) Button MOUSE")
b.setWidth(50)
action for onscreen button press
<<<<<<<<<<<<<<<<<<<<<<< end of BUTTONCHECK
>>>>>>>>>>>>>>> check the open serial port >>>>>>>>>>
Funktionen CHECKSERIAL() - kontroller för data från Arduino
void checkSerial()
inside checkSerial()")
>>>>>> see if the port is sending you stuff
while (port.available () > 0)
String inByte = port.readString()
Safe from OUSIDE IF . inByte = "+inByte)
int w=int(random(150))
b.setWidth(w)
port.clear()
sendTweet ("physical Button")
end try
Check serial exception = "+e)
<<<<<<<<<<<<<<<<<<<<< end checkSerial <<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>> load remote admin settings >>>>>>>>>>>>>>
Fungera LOADREMOTESETTINGS() - drar kontrollera data från Google spreadsheetsdata
String checkRandomSpeech = adminSettings[8]
if ((checkRandomSpeech.equals(adminSettings[8]))!=true)
tts.speak(adminSettings[8])
println("adminSettings["+i+"]= "+adminSettings[i])
end for
if (adminSettings[5].equals("h"))
use hashtag for search")
queryString = adminSettings[0]
queryType = "hashtag"
use username phrase for search")
queryString = adminSettings[1]
queryType = "username"
use search term for search")
queryString = adminSettings[2]
queryType = "search term"
now load load fortune fragments
String frag1 []= loadStrings ("https:docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdDQ3cUZ5Y2RMTm9RSXNrdElZTjN5R1E&output=txt")
for (int ff1=0 ff1
fortFrags1.add(frag1[ff1])
Fortune Frag1 = "+fortFrags1.get(ff1))
String frag2 []= loadStrings ("https:docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdGFQLTFhMUVqTTlkTjlRVUN4c3JtOGc&output=txt")
for (int ff2=0 ff2
fortFrags2.add(frag2[ff2])
Fortune Frag2 = "+frag2[ff2])
Fortune Frag1 = "+fortFrags2.get(ff2))
String frag3 []= loadStrings ("https:docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdFE0Qm1yYmhyYWJETVJsSHJIOGFMQ3c&output=txt")
for (int ff3=0 ff3
fortFrags3.add(frag3[ff3])
Fortune Frag3 = "+frag3[ff3])
String frag4 []= loadStrings ("https:docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdG9KTnhLS2Zvbk5HNXp2RmRpeUZtTUE&output=txt")
for (int ff4=0 ff4
fortFrags4.add(frag4[ff4])
Fortune Frag4 = "+frag4[ff4])
end if
no CONNECTION")
>>>>
LOADREMOTESTOPWORDS() - import filterlistan stopword
String stopWordsLoader [] = loadStrings("https:docs.google.com/spreadsheet/pub?key=0AgTXh43j7oFVdFByYk41am9jRnRkeU9LWnhjZFJTOEE&output=txt")
for (int i = 0 i < stopWordsLoader.length i++)
stop
stopWords.add(stopWordsLoader[i])
println("stopWords["+i+"]= "+stopWords.get(i)+". Length now: "+stopWords.size())
loadstopWordsCheckInt=false
println("jjjjjjjjjjjjj")