-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from travisbrown/topic/wayback-rs
Begin integrating wayback-rs
- Loading branch information
Showing
34 changed files
with
553 additions
and
2,581 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
use chrono::Utc; | ||
use clap::Parser; | ||
use futures::TryStreamExt; | ||
use futures_locks::Mutex; | ||
use std::fs::File; | ||
use wayback_rs::cdx::IndexClient; | ||
|
||
const PAGE_SIZE: usize = 150000; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
let opts: Opts = Opts::parse(); | ||
let _ = cancel_culture::cli::init_logging(opts.verbose)?; | ||
let client = IndexClient::default(); | ||
|
||
let output_path = opts | ||
.output | ||
.unwrap_or_else(|| format!("{}.csv", Utc::now().timestamp())); | ||
let output = Mutex::new(csv::WriterBuilder::new().from_writer(File::create(output_path)?)); | ||
|
||
client | ||
.stream_search(&opts.query, PAGE_SIZE) | ||
.map_err(Error::from) | ||
.try_for_each(|item| { | ||
let output = output.clone(); | ||
async move { | ||
let mut output = output.lock().await; | ||
output.write_record(item.to_record())?; | ||
|
||
Ok(()) | ||
} | ||
}) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error("I/O error: {0:?}")] | ||
Io(#[from] std::io::Error), | ||
#[error("CDX error: {0:?}")] | ||
IndexClient(#[from] wayback_rs::cdx::Error), | ||
#[error("CSV writing error: {0:?}")] | ||
Csv(#[from] csv::Error), | ||
#[error("Log initialization error: {0:?}")] | ||
LogInitialization(#[from] log::SetLoggerError), | ||
} | ||
|
||
#[derive(Parser)] | ||
#[clap(name = "cdxdl", version, author)] | ||
struct Opts { | ||
/// Level of verbosity | ||
#[clap(short, long, parse(from_occurrences))] | ||
verbose: i32, | ||
/// Query URL | ||
#[clap(short, long)] | ||
query: String, | ||
/// Output file (defaults to <timestamp>.csv) | ||
#[clap(short, long)] | ||
output: Option<String>, | ||
} |
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
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
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
Oops, something went wrong.