done
This commit is contained in:
commit
394726b47e
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
result*
|
||||||
1122
Cargo.lock
generated
Normal file
1122
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "quick-start"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
reqwest = { version = "0.11", features = ["blocking", "json"] }
|
||||||
121
flake.lock
generated
Normal file
121
flake.lock
generated
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"advisory-db": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709733674,
|
||||||
|
"narHash": "sha256-wmbzUBiecUofJaPLEZnKrfvxxjrxrpBPz9plt2K+Fr4=",
|
||||||
|
"owner": "rustsec",
|
||||||
|
"repo": "advisory-db",
|
||||||
|
"rev": "120db258e97454f900dff7cb8eb1b61a134f3eb0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "rustsec",
|
||||||
|
"repo": "advisory-db",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"crane": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709610799,
|
||||||
|
"narHash": "sha256-5jfLQx0U9hXbi2skYMGodDJkIgffrjIOgMRjZqms2QE=",
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"rev": "81c393c776d5379c030607866afef6406ca1be57",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fenix": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"rust-analyzer-src": []
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709792596,
|
||||||
|
"narHash": "sha256-DQL1KJ9AaoQjwMkZkSBrW9/az2dwbbBnhNIbIzgeDIE=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"rev": "221fedb628b1e86e88d8fbfbd20b699448e58fa9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709126324,
|
||||||
|
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709780214,
|
||||||
|
"narHash": "sha256-p4iDKdveHMhfGAlpxmkCtfQO3WRzmlD11aIcThwPqhk=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "f945939fd679284d736112d3d5410eb867f3b31c",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"advisory-db": "advisory-db",
|
||||||
|
"crane": "crane",
|
||||||
|
"fenix": "fenix",
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
159
flake.nix
Normal file
159
flake.nix
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
{
|
||||||
|
description = "Build a cargo project";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
crane = {
|
||||||
|
url = "github:ipetkov/crane";
|
||||||
|
inputs = {
|
||||||
|
#flake-utils.follows = "flake-utils";
|
||||||
|
nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
fenix = {
|
||||||
|
url = "github:nix-community/fenix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
inputs.rust-analyzer-src.follows = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
advisory-db = {
|
||||||
|
url = "github:rustsec/advisory-db";
|
||||||
|
flake = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }:
|
||||||
|
let
|
||||||
|
toolchain = system: (fenix
|
||||||
|
.packages
|
||||||
|
.${system}
|
||||||
|
.fromToolchainName
|
||||||
|
{
|
||||||
|
name = "nightly-2024-02-28";
|
||||||
|
sha256 = "sha256-Q/cX94ZIr486z4i5jhmJa44NVALWBoJcMAVic4KfuxA=";
|
||||||
|
});
|
||||||
|
in
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
|
||||||
|
craneLib = crane.lib.${system}.overrideToolchain (toolchain system).toolchain;
|
||||||
|
src = craneLib.cleanCargoSource (craneLib.path ./.);
|
||||||
|
|
||||||
|
# Common arguments can be set here to avoid repeating them later
|
||||||
|
commonArgs = {
|
||||||
|
inherit src;
|
||||||
|
strictDeps = true;
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
pkgs.openssl
|
||||||
|
# Add additional build inputs here
|
||||||
|
] ++ lib.optionals pkgs.stdenv.isDarwin [
|
||||||
|
# Additional darwin specific inputs can be set here
|
||||||
|
pkgs.libiconv
|
||||||
|
];
|
||||||
|
|
||||||
|
# Additional environment variables can be set directly
|
||||||
|
# MY_CUSTOM_VAR = "some value";
|
||||||
|
};
|
||||||
|
|
||||||
|
craneLibLLvmTools =
|
||||||
|
craneLib.overrideToolchain
|
||||||
|
((toolchain system).withComponents [
|
||||||
|
"cargo"
|
||||||
|
"clippy"
|
||||||
|
"llvm-tools"
|
||||||
|
"rustc"
|
||||||
|
"rust-analyzer"
|
||||||
|
"rustfmt"
|
||||||
|
]);
|
||||||
|
# Build *just* the cargo dependencies, so we can reuse
|
||||||
|
# all of that work (e.g. via cachix) when running in CI
|
||||||
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||||
|
|
||||||
|
# Build the actual crate itself, reusing the dependency
|
||||||
|
# artifacts from above.
|
||||||
|
my-crate = craneLib.buildPackage (commonArgs // {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
});
|
||||||
|
in
|
||||||
|
{
|
||||||
|
checks = {
|
||||||
|
# Build the crate as part of `nix flake check` for convenience
|
||||||
|
inherit my-crate;
|
||||||
|
|
||||||
|
# Run clippy (and deny all warnings) on the crate source,
|
||||||
|
# again, resuing the dependency artifacts from above.
|
||||||
|
#
|
||||||
|
# Note that this is done as a separate derivation so that
|
||||||
|
# we can block the CI if there are issues here, but not
|
||||||
|
# prevent downstream consumers from building our crate by itself.
|
||||||
|
my-crate-clippy = craneLib.cargoClippy (commonArgs // {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
||||||
|
});
|
||||||
|
|
||||||
|
my-crate-doc = craneLib.cargoDoc (commonArgs // {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
});
|
||||||
|
|
||||||
|
# Check formatting
|
||||||
|
my-crate-fmt = craneLib.cargoFmt {
|
||||||
|
inherit src;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Audit dependencies
|
||||||
|
my-crate-audit = craneLib.cargoAudit {
|
||||||
|
inherit src advisory-db;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Audit licenses
|
||||||
|
my-crate-deny = craneLib.cargoDeny {
|
||||||
|
inherit src;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Run tests with cargo-nextest
|
||||||
|
# Consider setting `doCheck = false` on `my-crate` if you do not want
|
||||||
|
# the tests to run twice
|
||||||
|
my-crate-nextest = craneLib.cargoNextest (commonArgs // {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
partitions = 1;
|
||||||
|
partitionType = "count";
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
packages = {
|
||||||
|
default = my-crate;
|
||||||
|
} // lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
|
||||||
|
my-crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
apps.default = flake-utils.lib.mkApp {
|
||||||
|
drv = my-crate;
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells.default = craneLib.devShell {
|
||||||
|
# Inherit inputs from checks.
|
||||||
|
checks = self.checks.${system};
|
||||||
|
|
||||||
|
# Additional dev-shell environment variables can be set directly
|
||||||
|
# MY_CUSTOM_DEVELOPMENT_VAR = "something else";
|
||||||
|
|
||||||
|
# Extra inputs can be added here; cargo and rustc are provided by default.
|
||||||
|
packages = [
|
||||||
|
# pkgs.ripgrep
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
89
src/main.rs
Normal file
89
src/main.rs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
use std::error::Error;
|
||||||
|
use std::fs::{self, File, OpenOptions};
|
||||||
|
use std::io::Write;
|
||||||
|
use std::time::Duration;
|
||||||
|
use std::{env, thread};
|
||||||
|
|
||||||
|
const URL: &str = "https://theboardr.com/events/";
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let last_event_id_filename =
|
||||||
|
env::var("LAST_EVENT_ID_PATH").expect("Environment variable LAST_EVENT_ID_PATH is not set");
|
||||||
|
|
||||||
|
let potential_cph_open_filename = env::var("POTENTIAL_CPH_OPEN_PATH")
|
||||||
|
.expect("Environment variable POTENTIAL_CPH_OPEN_PATH is not set");
|
||||||
|
|
||||||
|
create_file_if_not_exists(&potential_cph_open_filename);
|
||||||
|
let last_checked_event_id = get_last_checked_event_id(&last_event_id_filename)
|
||||||
|
.expect("Failed to get last checked event id");
|
||||||
|
let most_recent_event_id: u64 =
|
||||||
|
find_most_recent_event_id(&potential_cph_open_filename, last_checked_event_id)
|
||||||
|
.expect("Failed to find most recent event id");
|
||||||
|
update_last_checked_event_id(&last_event_id_filename, most_recent_event_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_last_checked_event_id(filename: &String) -> Result<u64, Box<dyn Error>> {
|
||||||
|
let last_checked_event_id = fs::read_to_string(filename)?.trim().parse()?;
|
||||||
|
Ok(last_checked_event_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_most_recent_event_id(cph_filepath: &str, last_checked: u64) -> Result<u64, Box<dyn Error>> {
|
||||||
|
let mut last_checked_event_id = last_checked;
|
||||||
|
let mut last_event_exists = true;
|
||||||
|
while last_event_exists == true {
|
||||||
|
last_checked_event_id += 1;
|
||||||
|
println!("Checking event: {}", last_checked_event_id);
|
||||||
|
let (exists, is_cph_open) = check_event(last_checked_event_id);
|
||||||
|
println!("- Exists: {}", exists);
|
||||||
|
println!("- CPH-OPEN: {}", is_cph_open);
|
||||||
|
last_event_exists = exists;
|
||||||
|
thread::sleep(Duration::from_secs(2));
|
||||||
|
if is_cph_open {
|
||||||
|
save_event_id(cph_filepath, last_checked_event_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(last_checked_event_id - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_event(id: u64) -> (bool, bool) {
|
||||||
|
let mut no_requests = 0;
|
||||||
|
let mut event_confirmed = false;
|
||||||
|
let mut matches = false;
|
||||||
|
while no_requests < 3 && !event_confirmed {
|
||||||
|
no_requests += 1;
|
||||||
|
let content = reqwest::blocking::get(format!("{URL}{id}"))
|
||||||
|
.expect("")
|
||||||
|
.text()
|
||||||
|
.expect("");
|
||||||
|
event_confirmed = content.contains(&format!("\"EventID\":{id}"));
|
||||||
|
matches = content.to_lowercase().contains(&format!("cph"))
|
||||||
|
|| content.to_lowercase().contains(&format!("copenhagen"));
|
||||||
|
if !event_confirmed {
|
||||||
|
thread::sleep(Duration::from_secs(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(event_confirmed, matches)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save_event_id(filename: &str, id: u64) {
|
||||||
|
let mut cph_file = OpenOptions::new()
|
||||||
|
.append(true)
|
||||||
|
.open(filename)
|
||||||
|
.expect(&format!("Failed to open file: {}", filename));
|
||||||
|
let id_to_write = format!("{}\n", id.to_string());
|
||||||
|
cph_file
|
||||||
|
.write(id_to_write.as_bytes())
|
||||||
|
.expect("Failed to write last checked event");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_last_checked_event_id(filename: &str, id: u64) {
|
||||||
|
let content = format!("{}\n", id.to_string());
|
||||||
|
fs::write(filename, content).expect("Failed to write last checked event");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_file_if_not_exists(filename: &str) {
|
||||||
|
if !std::path::Path::new(filename).exists() {
|
||||||
|
// If the file doesn't exist, create it
|
||||||
|
File::create(filename).expect("");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user