forked from infinit/elle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_wikipedia.cc
52 lines (50 loc) · 1.18 KB
/
get_wikipedia.cc
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
#include <elle/json/json.hh>
#include <reactor/http/Request.hh>
#include <reactor/http/exceptions.hh>
#include <reactor/scheduler.hh>
int
main()
{
reactor::Scheduler sched;
reactor::Thread t(
sched, "main",
[]
{
try
{
reactor::http::Request r("https://en.wikipedia.org/w/api.php",
reactor::http::Method::GET);
r.query_string({
{"format", "json"},
{"action", "query"},
{"prop", "extracts"},
{"explaintext", ""},
{"exintro", ""},
{"titles", "JSON"}
});
r.finalize();
if (r.status() != reactor::http::StatusCode::OK)
elle::err("quering %s failed", r);
std::cout << elle::json::pretty_print(elle::json::read(r)) << std::endl;
}
catch (reactor::http::ResolutionFailure const& e)
{
std::cerr << "Unable to resolve " << e.url() << std::endl;
throw;
}
catch (reactor::http::RequestError const& e)
{
std::cerr << "Unable to get " << e.url() << std::endl;
throw;
}
});
try
{
sched.run();
}
catch (...)
{
return 1;
}
return 0;
}