我正在创建一个 twitter 提要,它将一次显示 5 条推文。
推文每五分钟更新一次。一旦找到新推文,我希望顶部的推文移出屏幕,新推文进入最后一个位置,每条推文都向上移动一个位置以允许这样做。
import com.francisli.processing.http.*;
HttpClient client;
HashMap Tweetzer = new HashMap();
int results_to_show = 5;
int updateTime = 10000;
int updateDiff = 0;
void setup()
{
size(612, 612);
textAlign(CENTER, CENTER);
}
void tweetUpdate()
{
if(millis() > (updateTime + updateDiff))
{
client = new HttpClient(this, "search.twitter.com");
client.GET("search.json?q=dublin&rpp="+results_to_show+"&result_type=recent");
updateDiff = millis();
}
}
void mouseReleased()
{
tweetUpdate();
}
void draw()
{
}
void responseReceived(HttpRequest request, HttpResponse response)
{
if(response.statusCode == 200)
{
JSONObject allresults;
allresults = response.getContentAsJSONObject();
//JSONObject timeline_tweets = response.getContentAsJSONObject();
for (int i=0; i<results_to_show; i++)
{
text(allresults.get("results").get(i).get("text").stringValue(), 50, 10+(i*100), 400, 400);
}
}
else
{
text("UH-OH" + response.getContentAsString(), 50, 50);
}
}