Skip to content

Instantly share code, notes, and snippets.

@kimukou
Created July 9, 2012 02:32
Show Gist options
  • Save kimukou/3073881 to your computer and use it in GitHub Desktop.
Save kimukou/3073881 to your computer and use it in GitHub Desktop.
hashtag realtime search
http://otter.topsy.com/credit.json
{
response: {
limit: 3000,
reset: 1341903600,
refresh_in_secs: 83684,
remaining: 2675
},
request: {
parameters: { },
response_type: "json",
resource: "credit",
url: "http://otter.topsy.com/credit.json"
}
}
free is 3000 limit/day(unique IP)
charge account 7000 limit/day
see) http://code.google.com/p/otterapi/wiki/RateLimit
どうも似たようなハッシュタグが多いと引っかかりにくいみたい<通常のTwitterのサーチ検索
Twitter4jの検索とは逆に古い順で取得されるので逆順につめておく必要があり
(最新をtopにしたい場合
firstpost_date等はunix timestampなので
String timeStamp = item.getString("firstpost_date");//jsonObject
java.util.Date time=new java.util.Date(Long.valueOf(timeStamp)*1000);
の形で変換
http://code.google.com/p/otterapi/
json形式で返却
h:hour
d:day
w:week
m:month
a:all
//1週間以内のハッシュタグを検索する場合
//world seach
http://otter.topsy.com/search.json?page=1&perpage=20&q=%23twitter4j&window=w
//japan only
http://otter.topsy.com/search.json?allow_lang=ja&page=1&perpage=20&q=%23twitter4j&window=w
例)
http://otter.topsy.com/search.json?allow_lang=ja&page=1&perpage=20&q=%23twitter4j&window=d
{
request: {
parameters: {
window: "d",
page: "1",
allow_lang: "ja",
q: "#twitter4j",
perpage: "20"
},
response_type: "json",
resource: "search",
url: "http://otter.topsy.com/search.json? allow_lang=ja&page=1&perpage=20&q=%23twitter4j&window=d"
},
response: {
window: "d",
page: 1,
total: 1,
perpage: 20,
last_offset: 1,
hidden: 0,
list: [
{
trackback_permalink: "http://twitter.com/xuwei_k/status/223334587613454336",
trackback_author_url: "http://twitter.com/xuwei_k",
content: "https://t.co/jpKhduZP #twitter4j 次からjava5以下のサポート打ちきるのか",
trackback_date: 1342082089,
topsy_author_img: "http://a0.twimg.com/profile_images/1931553270/xuwei_normal.gif",
hits: 1,
topsy_trackback_url: "http://topsy.com/trackback?url=https%3A%2F%2Fgroups.google.com%2Fforum%2F%3Ffromgroups%23%21topic%2Ftwitter4j-j%2F39QwGtXkNno&utm_source=otter",
firstpost_date: 1342082089,
url: "https://groups.google.com/forum/?fromgroups#!topic/twitter4j-j/39QwGtXkNno",
trackback_author_nick: "xuwei_k",
highlight: "https://t.co/jpKhduZP <span class="highlight-term">#twitter4j</span> 次からjava5以下のサポート打ちきるのか ",
topsy_author_url: "http://topsy.com/twitter/xuwei_k?utm_source=otter",
trackback_author_name: "Kenji Yoshida",
mytype: "link",
score: 6.46934,
trackback_total: 1,
title: "https://t.co/jpKhduZP #twitter4j 次からjava5以下のサポート打ちきるのか"
}
],
offset: 0
}
}
class TopsyBean{
public String screen_name;
public String user_name;
public String text;
public Date date;
public String toString(){
StringBuilder sb = new StringBuilder();
sb.append(screen_name);
sb.append(",");
sb.append(user_name);
sb.append(",");
sb.append(text);
sb.append(" \n");
sb.append(df.format(date));
return sb.toString();
}
}
public class TopsyBeanComparator implements Comparator<TopsyBean> {
//逆順なのでマイナスをかける
public int compare(TopsyBean now, TopsyBean other) {
if(now==null && other==null)return 0;
if(now!=null && other==null)return 1;//-1;
if(now==null && other!=null)return -1;//1;
if(now.date==null && other.date==null)return 0;
if(now.date!=null && other.date==null)return 1;//-1;
if(now.date==null && other.date!=null)return -1;//1;
return now.date.compareTo(other.date) * -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment