Skip to content

CC-NEWS support and validation for crawl reference #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ fn crawl_name_format(crawl: &str) -> Result<String, String> {
let main_re = Regex::new(r"^(CC\-MAIN)\-([0-9]{4})\-([0-9]{2})$").unwrap();
let news_re = Regex::new(r"^(CC\-NEWS)\-([0-9]{4})\-([0-9]{2})$").unwrap();

if !(main_re.is_match(crawl) || news_re.is_match(crawl)) {
return Err("Please use the CC-MAIN-YYYY-WW or the CC-NEWS-YYYY-MM format, make sure your input is propely capitalized".to_string());
let crawl_ref = crawl.to_uppercase();

if !(main_re.is_match(&crawl_ref) || news_re.is_match(&crawl_ref)) {
return Err("Please use the CC-MAIN-YYYY-WW or the CC-NEWS-YYYY-MM format.".to_string());
} else {
return Ok(crawl.to_owned());
return Ok(crawl_ref);
}
}
16 changes: 10 additions & 6 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,21 @@ pub async fn download_paths(mut options: DownloadOptions<'_>) -> Result<(), Down
let resp = client.head(url.as_str()).send().await?;
match resp.status() {
status if status.is_success() => (),
status if status.is_client_error() => {
status if status.as_u16() == 404 => {
return Err(format!(
"\n\nThe reference combination you requested:\n\tCRAWL: {}\n\tSUBSET: {}\n\tURL: {}\n\nDoesn't seem to exist or it is currently not accessible.\n\tError Code: {} {}",
"\n\nThe reference combination you requested:\n\tCRAWL: {}\n\tSUBSET: {}\n\tURL: {}\n\nDoesn't seem to exist or it is currently not accessible.\n\tError code: {} {}",
snapshot_original_ref, options.data_type, url, status.as_str(), status.canonical_reason().unwrap_or("")
)
.into());
}
_ => {
return Err(
format!("Couldn't download URL: {}. Error: {:?}", url, resp.status()).into(),
);
status => {
return Err(format!(
"Couldn't download URL: {}. Error code: {} {}",
url,
status.as_str(),
status.canonical_reason().unwrap_or("")
)
.into());
}
}

Expand Down