6 |
import java.util.ArrayList; |
import java.util.ArrayList; |
7 |
import java.util.Collections; |
import java.util.Collections; |
8 |
import java.util.Date; |
import java.util.Date; |
|
import java.util.Formatter; |
|
9 |
import java.util.Locale; |
import java.util.Locale; |
10 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
11 |
|
|
17 |
import net.spy.memcached.MemcachedClient; |
import net.spy.memcached.MemcachedClient; |
18 |
|
|
19 |
import com.gc.android.market.api.MarketSession; |
import com.gc.android.market.api.MarketSession; |
|
import com.gc.android.market.api.MarketSession.Callback; |
|
|
import com.gc.android.market.api.model.Market.App; |
|
20 |
import com.gc.android.market.api.model.Market.AppsRequest; |
import com.gc.android.market.api.model.Market.AppsRequest; |
|
import com.gc.android.market.api.model.Market.AppsResponse; |
|
21 |
import com.gc.android.market.api.model.Market.CommentsRequest; |
import com.gc.android.market.api.model.Market.CommentsRequest; |
22 |
import com.gc.android.market.api.model.Market.ResponseContext; |
|
23 |
|
|
24 |
|
|
25 |
public class ShowStats extends HttpServlet { |
public class ShowStats extends HttpServlet { |
56 |
} |
} |
57 |
return response; |
return response; |
58 |
} |
} |
59 |
|
|
60 |
|
private void loadComments(String appId, MarketSession session, String locale, ArrayList<CommentBean> commentBeans) { |
61 |
|
CommentCallback commentsCb = new CommentCallback(); |
62 |
|
commentsCb.setList( commentBeans ); |
63 |
|
|
64 |
|
commentsCb.setLocale( locale ); |
65 |
|
session.setLocale( new Locale(locale) ); |
66 |
|
|
67 |
|
|
68 |
|
int start = 0; |
69 |
|
do { |
70 |
|
int count = 10; |
71 |
|
if (start > 0) |
72 |
|
count = Math.min(10, commentsCb.getEntryCount() ); |
73 |
|
|
74 |
|
//log.warning("count=" + count + " start=" + start + " " + locale); |
75 |
|
CommentsRequest commentsRequest = CommentsRequest.newBuilder() |
76 |
|
.setAppId(appId) |
77 |
|
.setStartIndex(start) |
78 |
|
.setEntriesCount(count) |
79 |
|
.build(); |
80 |
|
|
81 |
|
session.append(commentsRequest, commentsCb); |
82 |
|
session.flush(); |
83 |
|
start +=10; |
84 |
|
|
85 |
|
if (start >= 20) |
86 |
|
break; //emergency brake |
87 |
|
|
88 |
|
} while ( start < commentsCb.getEntryCount() ); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
protected String doLookupWorker(String appId) { |
protected String doLookupWorker(String appId) { |
103 |
.setWithExtendedInfo(true) |
.setWithExtendedInfo(true) |
104 |
.build(); |
.build(); |
105 |
|
|
|
CommentsRequest commentsRequest = CommentsRequest.newBuilder() |
|
|
.setAppId(appId) |
|
|
.setStartIndex(0) |
|
|
.setEntriesCount(10) |
|
|
.build(); |
|
|
|
|
106 |
|
|
107 |
|
AppsCallback appsCb = new AppsCallback() ; |
108 |
|
appsCb.setStringBuffer(sb); |
|
Callback<AppsResponse> appsCb = new Callback<AppsResponse>() { |
|
|
@Override |
|
|
public void onResult(ResponseContext context, AppsResponse response) { |
|
|
//System.out.println("Response : " + response); |
|
|
//sb.append("Response: " + response + "\n"); |
|
|
|
|
|
Formatter form = new Formatter(sb); |
|
|
App app = response.getApp(0); |
|
|
sb.append( "<h2>" + app.getTitle() + "</h2>"); |
|
|
sb.append("Ver: " + app.getVersion() + " (" + app.getVersionCode() + ")\n" ); |
|
|
sb.append("Ratingcount: " + app.getRatingsCount() + "\n"); |
|
|
|
|
|
sb.append("Rating: " ); |
|
|
double rating = Double.parseDouble( app.getRating() ); |
|
|
form.format("%.4f", rating); |
|
|
sb.append("\n"); |
|
|
|
|
|
sb.append("Downloads: " + app.getExtendedInfo().getDownloadsCountText() + " (" + app.getExtendedInfo().getDownloadsCount() + ")\n" ); |
|
|
|
|
|
sb.append("\n"); |
|
|
|
|
|
} |
|
|
}; |
|
109 |
|
|
110 |
ArrayList<CommentBean> commentBeans = new ArrayList<CommentBean>(); |
ArrayList<CommentBean> commentBeans = new ArrayList<CommentBean>(); |
111 |
|
|
|
CommentCallback commentsCb = new CommentCallback(); |
|
|
commentsCb.setList( commentBeans ); |
|
112 |
|
|
|
commentsCb.setLocale("en"); |
|
|
session.setLocale( Locale.ENGLISH ); |
|
113 |
|
|
114 |
session.append(appsRequest, appsCb); |
session.append(appsRequest, appsCb); |
|
session.append(commentsRequest, commentsCb); |
|
115 |
session.flush(); |
session.flush(); |
116 |
|
|
117 |
commentsCb.setLocale( "da" ); |
loadComments(appId, session, "da", commentBeans); |
118 |
session.setLocale( new Locale("da") ); |
loadComments(appId, session, "en", commentBeans); |
|
session.append(commentsRequest, commentsCb); |
|
|
session.flush(); |
|
119 |
|
|
120 |
Collections.sort(commentBeans); |
Collections.sort(commentBeans); |
121 |
|
|
128 |
sb.append("\n"); |
sb.append("\n"); |
129 |
|
|
130 |
} |
} |
131 |
|
sb.append("Comments: " + commentBeans.size() ); |
132 |
|
|
133 |
|
|
134 |
return sb.toString(); |
return sb.toString(); |