Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyBanks committed Feb 16, 2020
1 parent 1675bba commit 6d41d9f
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions src/bin/speedruns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,35 @@
clippy::result_unwrap_used
)]

use std::error::Error;

#[allow(unused)] use log::{debug, error, info, trace, warn};

mod import;
mod scrape;
mod serve;

#[derive(argh::FromArgs, PartialEq, Debug)]
/// Tools for importing and serving some data from the speedrun.com API.
pub struct Args {
#[argh(subcommand)]
subcommand: Subcommand,
use std::{collections::BTreeMap, rc::Rc, sync::Arc};

/// silence log output except for errors. overrides --verbose and RUST_LOG.
#[argh(switch, short = 'q')]
quiet: bool,
struct MyApp {
database: Arc<Database>,
}

/// enables maximum logging for our code and debug logging for dependencies. overrides
/// RUST_LOG.
#[argh(switch, short = 'v')]
verbose: bool,
impl MyApp {
// requirement: we need this to be able to keep running even if we update the
// database, ideally in a consistent way.
// so sleep for 5 seconds
async fn handle_request(self) -> String {
"hello world".to_string()
}
}

#[derive(argh::FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
pub enum Subcommand {
Download(DownloadArgs),
Import(import::Args),
Serve(serve::Args),
struct Database {
table_user: BTreeMap<u64, User>,
index_user_by_name: BTreeMap<String, u64>,
}

#[derive(argh::FromArgs, PartialEq, Debug)]
/// Fetches/updates a local mirror of speedrun.com API content. This just stores the JSON
/// representation of each item as-is, it doesn't make any assumptions about their structure
/// beyond the existence of a string "id" value. This stores everything in-memory, it's not
/// memory-efficient.
#[argh(subcommand, name = "download")]
pub struct DownloadArgs {}
struct User {
id: u64,
name: String,
}

#[actix_rt::main]
async fn main() -> Result<(), Box<dyn Error>> {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Args = argh::from_env();

if args.quiet {
Expand All @@ -59,17 +46,22 @@ async fn main() -> Result<(), Box<dyn Error>> {

pretty_env_logger::init();

match args.subcommand {
Subcommand::Download(_args) => {
scrape::main()?;
}
Subcommand::Import(args) => {
import::main(args)?;
}
Subcommand::Serve(args) => {
serve::main(args).await?;
}
}
let mut app = MyApp::new();

//

Ok(())
}

#[derive(argh::FromArgs, PartialEq, Debug)]
/// Tools for importing and serving some data from the speedrun.com API.
pub struct Args {
/// silence log output except for errors. overrides --verbose and RUST_LOG.
#[argh(switch, short = 'q')]
quiet: bool,

/// enables maximum logging for our code and debug logging for dependencies. overrides
/// RUST_LOG.
#[argh(switch, short = 'v')]
verbose: bool,
}

0 comments on commit 6d41d9f

Please sign in to comment.