|
|
|
@ -1,10 +1,20 @@
|
|
|
|
|
use utils::error::Result;
|
|
|
|
|
|
|
|
|
|
use actix_web::{get, http::header, web, App, HttpResponse, HttpServer, Responder};
|
|
|
|
|
use clap::Parser;
|
|
|
|
|
use rand::seq::SliceRandom;
|
|
|
|
|
|
|
|
|
|
pub const BING: &str = "https://www.bing.com/images/search";
|
|
|
|
|
|
|
|
|
|
/// An API for fetching images of a query, sourced from Microsoft Bing.
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
|
#[command(author, version, about, long_about = None)]
|
|
|
|
|
struct Args {
|
|
|
|
|
/// The port at which to run.
|
|
|
|
|
#[arg(short, long, default_value_t=3002)]
|
|
|
|
|
port: u16,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn get_images(query: &str) -> reqwest::Result<Vec<String>> {
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
use scraper::{Html, Selector};
|
|
|
|
@ -70,7 +80,7 @@ async fn main() -> std::io::Result<()> {
|
|
|
|
|
.service(route_query_random)
|
|
|
|
|
.service(route_query_index)
|
|
|
|
|
})
|
|
|
|
|
.bind(("127.0.0.1", 3002))?
|
|
|
|
|
.bind(("127.0.0.1", Args::parse().port))?
|
|
|
|
|
.run()
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|