(value).value_or(default_max_time_s) };
} else if (key == "--word") {
gd_word = value;
}
}
};
void fetch_images(images_params const& params)
{
cpr::Response const r = cpr::Get(
cpr::Url{ "https://www.bing.com/images/search"sv },
cpr::Parameters{ { "q", params.gd_word }, { "mkt", "ja-JP" } },
cpr::Header{ { "User-Agent", "Mozilla/5.0" } },
cpr::VerifySsl{ false },
cpr::Timeout{ params.max_time }
);
raise_if(r.status_code != 200, "Couldn't connect to Bing.");
static std::regex const img_re("]*class=\"mimg[^<>]*>");
auto images_begin = std::sregex_iterator(std::begin(r.text), std::end(r.text), img_re);
auto images_end = std::sregex_iterator();
fmt::print("\n");
for (auto const& match: std::ranges::subrange(images_begin, images_end) | std::views::take(5)) {
fmt::print("{}\n", match.str());
}
fmt::print("
\n");
fmt::print("{}\n", css_style);
}
void images(std::span const args)
{
try {
fetch_images(fill_args(args));
} catch (gd::help_requested const& ex) {
fmt::print(help_text);
} catch (gd::runtime_error const& ex) {
fmt::print("{}\n", ex.what());
}
}