EnvVars for life

This commit is contained in:
Julius 2019-12-04 10:11:49 +01:00
parent 777e941469
commit ecf36d442e
5 changed files with 24 additions and 5 deletions

3
.env.example Normal file
View file

@ -0,0 +1,3 @@
WH_TOKEN=Webhook token
WH_ID=Webhook server id
WH_SESSION=aoc session cookie

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
/target /target
**/*.rs.bk **/*.rs.bk
.idea/ .idea/
.env

7
Cargo.lock generated
View file

@ -14,6 +14,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "aoclog" name = "aoclog"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)",
@ -257,6 +258,11 @@ dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "dtoa" name = "dtoa"
version = "0.4.4" version = "0.4.4"
@ -1744,6 +1750,7 @@ dependencies = [
"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" "checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
"checksum ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113" "checksum ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113"
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
"checksum dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
"checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9" "checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9"

View file

@ -10,6 +10,7 @@ edition = "2018"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
reqwest = "0.9" reqwest = "0.9"
dotenv = "0.15"
[dependencies.serenity] [dependencies.serenity]
default-features = false default-features = false

View file

@ -2,6 +2,7 @@ extern crate reqwest;
extern crate serde; extern crate serde;
extern crate serde_json; extern crate serde_json;
use dotenv;
use std::collections::HashMap; use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
@ -9,6 +10,7 @@ use serde::{Deserialize, Deserializer};
use serde::de::{self}; use serde::de::{self};
use serde::export::fmt::Display; use serde::export::fmt::Display;
use serde_json::Value; use serde_json::Value;
use std::env;
#[derive(Deserialize, PartialEq, Debug)] #[derive(Deserialize, PartialEq, Debug)]
struct AOCRequest { struct AOCRequest {
@ -46,14 +48,19 @@ fn from_str<'de, T, D>(deserializer: D) -> Result<T, D::Error>
fn main() { fn main() {
dotenv::dotenv().ok();
let token = env::var_os("WH_TOKEN").expect("Token not set!");
let id = env::var_os("WH_ID").expect("ID not set!");
let sess = env::var_os("WH_SESSION").expect("Session not set!");
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let json: AOCRequest = client.get("https://adventofcode.com/2019/leaderboard/private/view/356604.json") let json: AOCRequest = client.get("https://adventofcode.com/2019/leaderboard/private/view/356604.json")
.header("Cookie", .header("Cookie",
"session=lol") format!("session={}", sess.as_os_str().to_str().expect("oof")))
.send().expect("Failed to send request").json().expect("Error parsing response"); .send().expect("Failed to send request").json().expect("Error parsing response");
//"https://discordapp.com/api/webhooks/651520885349548044/EY0yz2fvWiViMr_mr1AhgTQ2xikC32U_ncEnpAy4sy7zlsq8hDFufYuynUjw22vbLHlQ"
let id = 651_520_885_349_548_044; let id = id.as_os_str().to_str().expect("ID is not an int").parse().expect("ID is not an int");
let token = "EY0yz2fvWiViMr_mr1AhgTQ2xikC32U_ncEnpAy4sy7zlsq8hDFufYuynUjw22vbLHlQ"; let token = token.to_str().expect("Token is not valid");
let http = serenity::http::Http::default(); let http = serenity::http::Http::default();
let mut wh = http.as_ref().get_webhook_with_token(id, token).expect("Cannot create webhook"); let mut wh = http.as_ref().get_webhook_with_token(id, token).expect("Cannot create webhook");