public
Created

public text box, twitter public information appliance

  • Download Gist
publictextbox.pde
Processing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
/* Public Text Box */
 
/*
 
contains portions of a simple Processing and Twitter thingy majiggy
RobotGrrl.com
Code licensed under:
CC-BY
 
update from dan, additional code, public domain.
 
*/
 
// First step is to register your Twitter application at dev.twitter.com
// Once registered, you will have the info for the OAuth tokens
// You can get the Access token info by clicking on the button on the
// right on your twitter app's page
 
// get library from http://www.sojamo.de/libraries/controlP5
// and http://www.superduper.org/processing/fullscreen_api/
import fullscreen.*;
FullScreen fs;
 
import controlP5.*;
ControlP5 controlP5;
String textValue = "";
Textfield myTextfield;
 
// This is where you enter your Oauth info
static String OAuthConsumerKey = "";
static String OAuthConsumerSecret = "";
 
// This is where you enter your Access Token info
static String AccessToken = "";
static String AccessTokenSecret = "";
 
//static means global
int x = 30;
PFont fontA;
static String[] pastTweets = new String[20];
static String thisTweet="";
int numTweets;
 
String myTimeline;
java.util.List statuses = null;
Twitter twitter = new TwitterFactory().getInstance();
RequestToken requestToken;
String[] theSearchTweets = new String[11];
 
 
Textlabel myTextlabelA;
Textlabel myTextlabelB;
 
void setup() {
controlP5 = new ControlP5(this);
 
myTextfield = controlP5.addTextfield("type msg here",10,60,350,50);
myTextfield.setFocus(true);
//myTextfield.
// controlP5.setControlFont(new ControlFont(createFont("Georgia",14), 14));
 
myTextlabelA = controlP5.addTextlabel("label","remaining chars = 140",240,114);
//myTextlabelB = controlP5.addTextlabel("label2","@publictextbox",10,10);
//myTextlabelA.setColorValue(0xffcccccc);
 
myTextlabelB = new Textlabel(this,"publictextbox",10,10,800,250);
 
//controlP5.addTextfield("textValue",100,200,200,20);
size(1200,700);
// size(640,480);
// Create the fullscreen object
fs = new FullScreen(this);
// enter fullscreen mode
fs.enter();
 
background(100);
//fontA = loadFont("Ziggurat-HTF-Black-32.vlw");
 
// Set the font and its size (in units of pixels)
//textFont(fontA, 32);
 
connectTwitter();
//sendTweet("Hey from processing test application");
getTimeline();
}
 
 
void draw() {
background(100);
int remChars=140-myTextfield.getText().length();
fill(50);
//text("type and then hit enter to tweet", 10, 20);
 
fill(200);
//rect(10,40,900,100);
//myTextlabelB = new Textlabel(this,"characters remaining " + remChars,20,74,300,200);
myTextlabelB.draw(this);
//yTextlabelA = new Textlabel(this,"----changed text with remChars = "+remChars,20,74,800,40);
//myTextlabelA.draw(this);
 
myTextlabelA.setValue("remaining chars = "+remChars);
 
 
//text("characters remaining " +remChars, 10, 50);
fill(0);
//keyTyped();
//println(myTextlabelA.isAutoClear());
 
fill(150);
text("the past", 10, 180);
for(int i=0; i<numTweets; i++)
{
text(pastTweets[i],10, i*30+210);
}
}
 
 
// Initial connection
void connectTwitter() {
 
twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
AccessToken accessToken = loadAccessToken();
twitter.setOAuthAccessToken(accessToken);
 
}
 
// Sending a tweet
void sendTweet(String t) {
 
try {
Status status = twitter.updateStatus(t);
println("Successfully updated the status to [" + status.getText() + "].");
} catch(TwitterException e) {
println("Send tweet: " + e + " Status code: " + e.getStatusCode());
}
 
}
 
 
// Loading up the access token
private static AccessToken loadAccessToken(){
return new AccessToken(AccessToken, AccessTokenSecret);
}
 
 
// Get your tweets
void getTimeline() {
String foo;
try {
statuses = twitter.getUserTimeline();
} catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
numTweets=statuses.size();
for(int i=0; i<numTweets; i++) {
Status status = (Status)statuses.get(i);
pastTweets[i] = status.getCreatedAt() + ": " + status.getText();
println(pastTweets[i]);
//println(status.getUser().getName() + ": " + status.getText());
// DATE
//date = status.getUser().getCreatedAt();
}
 
}
 
 
// Search for tweets
void getSearchTweets() {
 
String queryStr = "@publictextbox";
 
try {
Query query = new Query(queryStr);
query.setRpp(10); // Get 10 of the 100 search results
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
 
for (int i=0; i<tweets.size(); i++) {
Tweet t = (Tweet)tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreatedAt();
theSearchTweets[i] = msg.substring(queryStr.length()+1);
 
println(theSearchTweets[i]);
}
 
} catch (TwitterException e) {
println("Search tweets: " + e);
}
 
}
 
void controlEvent(ControlEvent theEvent) {
println("controlEvent: accessing a string from controller '"+theEvent.controller().name()+"': "+theEvent.controller().stringValue());
sendTweet(theEvent.controller().stringValue());
getTimeline();
}
 
 
public void texting(String theText) {
// receiving text from controller texting
println("a textfield event for controller 'texting': "+theText);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.