-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "voting-setup" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "4.5.3", features = ["derive"] } | ||
libsums = { git = "https://github.com/HackSocNotts/libsums.git", version = "0.5.0" } | ||
mongodb = "2.8.2" | ||
tokio = { version = "1.36.0", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use clap::Parser; | ||
use libsums::client::SumsClient; | ||
use mongodb::{ | ||
bson::{doc, Document}, | ||
options::ClientOptions, | ||
Client, | ||
}; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version, about, long_about = None)] | ||
struct Args { | ||
/// The MongoDB username | ||
mongo_user: String, | ||
|
||
/// The MongoDB password | ||
mongo_pass: String, | ||
|
||
/// The MongoDB URL. Note that this isn't a full URL (e.g., mongodb://...), but is just the | ||
/// address name. | ||
mongo_url: String, | ||
|
||
/// The Webdriver address for libsums | ||
webdriver_address: String, | ||
|
||
/// The browser being used for libsums (probably chrome) | ||
browser_name: String, | ||
|
||
/// The username to login to SUMS with. Must be a valid HackSoc commitee member. | ||
sums_username: String, | ||
|
||
/// The password for the SUMS user. | ||
sums_password: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let args = Args::parse(); | ||
|
||
let client_options = ClientOptions::parse(format!( | ||
"mongodb://{}:{}@{}/hacksoc?authSource=admin&retryWrites=true&w=majority", | ||
args.mongo_user, args.mongo_pass, args.mongo_url, | ||
)) | ||
.await | ||
.expect("Faileed to parse client options!"); | ||
|
||
let mongodb_client = | ||
Client::with_options(client_options).expect("Failed to create MongoDB client!"); | ||
|
||
let members_collection = mongodb_client | ||
.database("Hacksoc") | ||
.collection::<Document>("members"); | ||
|
||
let sums_client = SumsClient::new(213, "http://localhost:4444", "chrome") | ||
.await | ||
.expect("Failed to create SUMS client!"); | ||
|
||
sums_client | ||
.authenticate(args.sums_username, args.sums_password) | ||
.await | ||
.expect("Failed to authenticate with SUMS!"); | ||
|
||
let members = sums_client.members().await.expect("Failed to get members!"); | ||
let member_bson = members | ||
.iter() | ||
.map(|member| doc! { "ID": &member.student_id }); | ||
|
||
members_collection | ||
.drop(None) | ||
.await | ||
.expect("Failed to drop members collection!"); | ||
|
||
members_collection | ||
.insert_many(member_bson, None) | ||
.await | ||
.expect("Failed to insert members!"); | ||
|
||
println!("Successfully inserted {} members", members.len()); | ||
} |