2020-10-16 17:12:14 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate rocket;
|
|
|
|
|
|
|
|
use dotenv::dotenv;
|
2020-10-16 18:24:44 +02:00
|
|
|
use rocket_contrib::templates::Template;
|
|
|
|
use serde::Serialize;
|
2020-10-16 17:12:14 +02:00
|
|
|
|
2020-10-16 18:24:44 +02:00
|
|
|
mod slack;
|
2020-10-16 17:12:14 +02:00
|
|
|
mod weather;
|
|
|
|
|
2020-10-16 18:24:44 +02:00
|
|
|
#[derive(Serialize)]
|
|
|
|
struct Context {}
|
|
|
|
|
2020-10-16 17:12:14 +02:00
|
|
|
#[get("/weather/<loc>")]
|
|
|
|
async fn get_weather(loc: String) -> Result<String, String> {
|
|
|
|
let sum = weather::get_summary(&loc).await?;
|
|
|
|
Ok(format!("The weather in {} is: {:?}", loc, sum))
|
|
|
|
}
|
|
|
|
|
2020-10-16 18:24:44 +02:00
|
|
|
#[get("/slack/<msg>")]
|
|
|
|
async fn set_status(msg: String) -> Result<String, String> {
|
|
|
|
slack::set_status(&msg).await?;
|
|
|
|
Ok("woohoo".to_owned())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/")]
|
|
|
|
async fn index() -> Template {
|
|
|
|
let ctx = Context {};
|
|
|
|
Template::render("index", &ctx)
|
|
|
|
}
|
|
|
|
|
2020-10-16 17:12:14 +02:00
|
|
|
#[rocket::launch]
|
|
|
|
fn rocket() -> rocket::Rocket {
|
|
|
|
dotenv().ok();
|
|
|
|
|
2020-10-16 18:24:44 +02:00
|
|
|
rocket::ignite()
|
|
|
|
.attach(Template::fairing())
|
|
|
|
.mount("/", routes![index, get_weather, set_status])
|
2020-10-16 15:13:43 +02:00
|
|
|
}
|