Compare commits
No commits in common. "ad331ee121413890e969bd1159811544557c9963" and "7da61ae3ab889f4349532add56debbf812c7fe69" have entirely different histories.
ad331ee121
...
7da61ae3ab
5 changed files with 17 additions and 49 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -873,7 +873,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prose_dl"
|
name = "prose_dl"
|
||||||
version = "0.2.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "prose_dl"
|
name = "prose_dl"
|
||||||
version = "0.2.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -20,9 +20,4 @@ folder named after your username:
|
||||||
$ prose_dl <username>
|
$ prose_dl <username>
|
||||||
```
|
```
|
||||||
|
|
||||||
Will download the special files too:
|
|
||||||
```bash
|
|
||||||
$ prose_dl -s <username>
|
|
||||||
```
|
|
||||||
|
|
||||||
More info with the `--help` option.
|
More info with the `--help` option.
|
||||||
|
|
|
@ -1,46 +1,23 @@
|
||||||
/// Download all the posts
|
/// Download all the posts from the raw endpoint
|
||||||
pub async fn download_posts(
|
pub async fn download_posts(posts: (String, Vec<String>), dir: String) {
|
||||||
posts: (String, Vec<String>),
|
|
||||||
dir: String,
|
|
||||||
download_special_files: bool,
|
|
||||||
) {
|
|
||||||
// Create folder, silently ignore if already exists
|
// Create folder, silently ignore if already exists
|
||||||
std::fs::create_dir(&dir).unwrap_or_default();
|
std::fs::create_dir(&dir).unwrap_or_default();
|
||||||
|
|
||||||
// Download all the posts
|
|
||||||
for post in posts.1 {
|
|
||||||
download(&posts.0, &dir, post, "md").await;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if specials files need to be downloaded
|
|
||||||
if download_special_files {
|
|
||||||
let special_files = [
|
|
||||||
(String::from("_readme"), "md"),
|
|
||||||
(String::from("_styles"), "css"),
|
|
||||||
];
|
|
||||||
|
|
||||||
for file in special_files {
|
|
||||||
download(&posts.0, &dir, file.0, file.1).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Download a file from the raw endpoint
|
|
||||||
async fn download(url: &String, output_dir: &String, post_name: String, extension: &str) {
|
|
||||||
// Endpoint name
|
// Endpoint name
|
||||||
let endpoint = "raw";
|
let endpoint = "raw";
|
||||||
|
|
||||||
let data = reqwest::get(format!("{}/{}/{}", url, endpoint, post_name))
|
for post in posts.1 {
|
||||||
.await
|
let mut file = std::fs::File::create(format!("{}/{}.md", dir, post)).unwrap();
|
||||||
.unwrap()
|
std::io::Write::write_all(
|
||||||
.text()
|
&mut file,
|
||||||
.await
|
reqwest::get(format!("{}/{}/{}", posts.0, endpoint, post))
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.text()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.as_bytes(),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if data != "post not found\n" {
|
|
||||||
// Write file with the content
|
|
||||||
let mut file =
|
|
||||||
std::fs::File::create(format!("{}/{}.{}", output_dir, post_name, extension)).unwrap();
|
|
||||||
std::io::Write::write_all(&mut file, data.as_bytes()).unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,6 @@ struct Cli {
|
||||||
/// Scheme: HTTP/HTTPS
|
/// Scheme: HTTP/HTTPS
|
||||||
#[clap(long, value_parser, default_value = "https")]
|
#[clap(long, value_parser, default_value = "https")]
|
||||||
scheme: String,
|
scheme: String,
|
||||||
|
|
||||||
/// Download special files
|
|
||||||
#[clap(short, takes_value = false)]
|
|
||||||
special_files: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -51,5 +47,5 @@ async fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Download the posts
|
// Download the posts
|
||||||
download::download_posts(posts, directory, cli.special_files).await;
|
download::download_posts(posts, directory).await;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue