C#-407
class B{void Main(string[] a){var o=0;for(int i=1;i<11;i++){var r=((System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(new Uri(string.Format(a[0]+"&page={0}",i)))).GetResponse();if(r.ContentLength>0){using(var s=new StreamReader(r.GetResponseStream()))foreach(Match m in Regex.Matches(s.ReadToEnd(),"bounty worth (.+?) "))o+=int.Parse(m.Value.Substring(m.Value.IndexOf('h')+2));}}Console.Write(o);}}
Stackoverflow.comを使用します。Gzip圧縮解除と異なる正規表現を除いて、以下と同じです。
テスト
> prog.exe http://stackoverflow.com/questions?pagesize=50&sort=featured
38150
奇妙なことに、以下とは異なる値を取得します。
C#-496
これは、gzip圧縮されたjsonのapi.stackexchangeを使用します。
using System.IO.Compression;class B{void Main(string[] a){var o=0;for(int i=1;i<11;i++){var r=((System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(new Uri(string.Format(a[0]+"&page={0}",i)))).GetResponse();if(r.ContentLength>0)using(var s=new StreamReader(new GZipStream(r.GetResponseStream(),CompressionMode.Decompress)))foreach(Match m in Regex.Matches(s.ReadToEnd(),@"bounty_amount"":(.+?),"))o+=int.Parse(m.Value.Substring(m.Value.IndexOf(':')+1).Replace(",",""));}Console.Write(o);}}
縮小されていない:
using System.IO.Compression;
class B
{
void Main(string[] a)
{
var o = 0;
for (int i=1; i<11; i++) {
var w = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(new Uri(string.Format(a[0]+"&page={0}",i)));
if(w.GetResponse().ContentLength > 0)
using(var s = new StreamReader(new GZipStream(w.GetResponse().GetResponseStream(),CompressionMode.Decompress)))
foreach(Match m in Regex.Matches(s.ReadToEnd(), @"bounty_amount"":(.+?),"))
o += int.Parse(m.Value.Substring(m.Value.IndexOf(':')+1).Replace(",", ""));
}
Console.Write(o);
}
}
テスト
デフォルトのページサイズ:
> prog.exe http://api.stackexchange.com/2.2/questions/featured?site=stackoverflow
25300
ページサイズ= 100:
> prog.exe "http://api.stackexchange.com/2.2/questions/featured?site=stackoverflow&pagesize=100"
37400