weatherstat/src/main.rs

40 lines
829 B
Rust
Raw Normal View History

#[macro_use]
extern crate rocket;
use dotenv::dotenv;
use rocket_contrib::templates::Template;
use serde::Serialize;
mod slack;
mod weather;
#[derive(Serialize)]
struct Context {}
#[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))
}
#[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)
}
#[rocket::launch]
fn rocket() -> rocket::Rocket {
dotenv().ok();
rocket::ignite()
.attach(Template::fairing())
.mount("/", routes![index, get_weather, set_status])
2020-10-16 15:13:43 +02:00
}